我有一个包含多列数据行的工作表。特别是一列,我们称之为“L”列主要有这两个值:
我的代码如下:
Sub CheckColumn()
Dim i
For i = 3 to 4001
If Cells(i, 12).Value <> xlErrNA And Cells(i, 12).Value <> "0" Then GoTo NoColor
Next i
With Activeworkbook.Activesheet.Tab
.Color = 255
.TintAndShade = 0
End With
Exit Sub
NoColor:
End Sub
但我所拥有的似乎并没有起作用。任何想法/建议/协助将不胜感激。
谢谢!
答案 0 :(得分:0)
Bebause xlErrNA
不正确检查#N / A值(相当于使用NA()
)
尝试这样的单发公式(参见Countif With Multiple OR Criteria)
Sub CheckColumn()
If Evaluate("Sum(COUNTIF(K3:K4001,{""=0"",""#N/A""}))") <> 3998 Then
With ActiveWorkbook.ActiveSheet.Tab
.Color = 255
.TintAndShade = 0
End With
End Sub
答案 1 :(得分:0)
感谢您的回答。只是fyi,根据你的回答,你错过了'End If'
但是通过你提供的链接,我能够弄清楚:
For I = 1 to ActiveWorkbook.Worksheets.Count
Activeworkbook.Worksheets(I).Select
iVal = Application.WorksheetFunction.CountIf(Range("K2:K4000"), "0") + Application.WorksheetFunction.CountIf(Range("K2:K4000"), "#N/A")
If iVal = 3999 Then
With ActiveWorkbook.ActiveSheet.Tab
.Color = 255
.TintAndShade = 0
End With
End If
Next I
再次感谢您的信息 - 非常感谢。
谢谢!