Link to home
Start Free TrialLog in
Avatar of mhdi
mhdi

asked on

Excel VBA - If cell is 0 then clear contents of range...

Hi,

I have a table on "Sheet2" within the range "B5:BH73".

I need a macro loop to iterate over each column.

It needs to check if row 10 = 0 then clear contents of cells 5 to 73 of that column.

I have the following so far:

For Each rng In Sheet("Sheet2").Range("B5:BH73").Columns
  'If cell 10 = 0 Then clear Cells 5 to 73
Next rng

Open in new window


How do I refer to cell 10 inside the For Loop so I can check its contents?

thanks
SOLUTION
Avatar of Ingeborg Hawighorst (Microsoft MVP / EE MVE)
Ingeborg Hawighorst (Microsoft MVP / EE MVE)
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mhdi
mhdi

ASKER

Thankyou. I tried both versions but ended up using ssaqibh's code.

@teylyn your code seemed to always delete the contents on the first sheet of the workbook.