Find text and Clear content in the following columns of the same row

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

Is there a way to create a vba code that will find text and clear contents in the preceding columns?

For instance, I want to search for the word "Completed" in column D. Once it finds this word, I will need it to go to columns E, F and G and clear the contents on the same row it found "Completed". So let's say that "Completed" was found in row 3, then I will need to clear the contents in columns E,F, G of row 3. Then move on to the next instance of the word "Completed" and do the same thing.

Is this possible?

Thank you
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Here is one way:
Code:
Sub ClearCompletedCells()
    
    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column D
    lr = Cells(Rows.Count, "D").End(xlUp).Row
    
'   Loop through all rows checking column D
    For r = 1 To lr
        If Cells(r, "D") = "Completed" Then
'           Clear columns E-G
            Range(Cells(r, "E"), Cells(r, "G")).ClearContents
        End If
    Next r
        
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
Works perfectly.

Thank you so much.
I came up with another way, but your way was faster.

Thank you
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,620
Latest member
dsubash

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top