jeudi 9 juillet 2015

Clear cell content in a range if value is negative

I'm triyng to make my macro able to clear cells if their value is negative. In particular, the macro should clear all negative cells in columns H to K until last row in column A.

I tried this code I've found on the net but I really don't know how to extend it to columns I to K (works only for column H).

Dim LC1 As Long, ColNum1 As Long
Application.ScreenUpdating = False
For ColNum1 = 8 To Cells(1, Columns.Count).End(xlToLeft).Column
  For LC1 = 2 To Cells(Rows.Count, ColNum1).End(xlUp).Row
     If Val(CStr(Cells(LC1, ColNum1))) < 0 Then Cells(LC1, ColNum1) = 0
  Next LC1
Next ColNum1
Application.ScreenUpdating = True

I tried to replicate this code changing each time the value ColNum# to 9, 10 and 11 but it's not working. Why?

Many thanks!

Aucun commentaire:

Enregistrer un commentaire