clear contents in one column based on text in another column

Barb Mick

New Member
Joined
Jan 25, 2018
Messages
14
Office Version
  1. 365
Hi,

If someone could help me? I'm looking for vba code to clear the contents of a cell in column A if the cell in column D has specific text.
ie If column D contains "Sample" then clear the contents of column A.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
How are the cells in col D being populated?
 
Upvote 0
I'm not sure that I understand the question. It's a text file dumped into excel that I'm trying to clean up unnecessary info and format.

I'm using this code to clear contents in one column if the cell in another is blank, but I need another line to clear contents if the cell has a certain word.

'(With rows 1 to 1000, if E is blank delete contents of column D)Columns("E:E").SpecialCells(xlCellTypeBlanks).Offset(, -1) = ""
 
Upvote 0
Ok, how about
Code:
Sub Barb_Mick()
   With Range("D1", Range("D" & Rows.count).End(xlUp))
      .Replace "Sample", "=xxxSample", xlWhole, , False, , False, False
      .SpecialCells(xlFormulas, xlErrors).Offset(, -3).ClearContents
      .Replace "=xxxSample", "Sample", xlWhole, , False, , False, False
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
How about
Code:
Sub Barb_Mick()
   With Range("D1", Range("D" & Rows.count).End(xlUp))
      .Replace "Sample", "=xxxSample", xlWhole, , False, , False, False
      .SpecialCells(xlFormulas, xlErrors).Offset(, -3).ClearContents
      .Replace "=xxxSample", "Sample", xlWhole, , False, , False, False
      .Offset(, -1).Value = Evaluate("if(" & .Address & "<>""TUBE"",""""," & .Offset(, -1).Address & ")")
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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