如果值为负值,则清除某个范围内的单元格内容

如果他们的价值是负面的,我会让我的macros能够清除细胞。 特别是,macros应清除列H到K中的所有负单元,直到列A中的最后一行。

我试过这个代码,我发现在networking上,但我真的不知道如何将其扩展到列I到K(只适用于列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 

我试图复制这个代码改变每次值ColNum#到9,10和11,但它不工作。 为什么?

这应该工作:

 ' Get last row of col A... Dim lastRow as long, r As Long, c As Long Range("A1").select lastRow = Cells.Find("*",SearchOrder:=xlByRows,SearchDirection:=xlPrevious).Row For r = 2 To lastRow For c = 8 To 11 If IsNumeric(Cells(r, c)) Then If Cells(r, c) < 0 Then Cells(r, c).ClearContents End If End If Next Next