Macro to clear cells

JEB85

Board Regular
Joined
Aug 13, 2010
Messages
228
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:

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,317
Office Version
  1. 365
Platform
  1. Windows
How about
Code:
Sub ClrCells()

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

End Sub
 

JEB85

Board Regular
Joined
Aug 13, 2010
Messages
228
Works great, thank you! If i need to the range to be specific, say rows 10:100, how would i tweak the code?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,317
Office Version
  1. 365
Platform
  1. Windows
Like this
Code:
Sub ClrCells()

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

End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,317
Office Version
  1. 365
Platform
  1. Windows
You're welcome
 

Watch MrExcel Video

Forum statistics

Threads
1,123,383
Messages
5,601,318
Members
414,441
Latest member
KellyTheKid

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
Top