Macro to clear cells

JEB85

Board Regular
Joined
Aug 13, 2010
Messages
238
Hi,

I'm looking for a macro that will clear the cell contents in columns B&C if the cell value in column A is blank.

So in the example below, i would like B2:C2 and B5:C5 clearing as A2 and A5 are both blank.

Is there a simple macro to do this please?

Column
A
B
C
Name
Test1
Test2
Row
1
A1
1
1
2
1
1
3
A3
1
1
4
A4
1
1
5
2
2
6
A6
7
A7
3
3
8
A8

<tbody>
</tbody>

Aplogies, the fomratting of the table above is not aligned!
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
How about
Code:
Sub ClrCells()

   With Columns(1).SpecialCells(xlBlanks)
      .Offset(, 1).ClearContents
      .Offset(, 2).ClearContents
   End With

End Sub
 
Upvote 0
Works great, thank you! If i need to the range to be specific, say rows 10:100, how would i tweak the code?
 
Upvote 0
Like this
Code:
Sub ClrCells()

   With [COLOR=#0000ff]Range("A10:A100")[/COLOR].SpecialCells(xlBlanks)
      .Offset(, 1).ClearContents
      .Offset(, 2).ClearContents
   End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,577
Messages
6,120,359
Members
448,956
Latest member
Adamsxl

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