奇怪的是,任何人都可以看到下面的VB代码有什么问题。
运行时错误5,无效的过程调用或参数
错误在下面的代码块中突出显示
wssheet1.Range("BC" & x).FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND(COUNTIF(Ratecard!Q:Q,BC3)=0,AN3>0) = TRUE"
以下是整个代码:
Sub TestLook()
Set wsWhiteCollar = ThisWorkbook.Worksheets("White Collar")
Set wssheet1 = ThisWorkbook.Worksheets("WEW")
wsWhiteCollar.Activate
'wssheet1.Activate
EndWC = wssheet1.Range("B" & Rows.Count).End(xlUp).Row 'i.e. column B last row 24 to 25 on my WEW table
Application.ScreenUpdating = False
For Each c In wsWhiteCollar.Range(wsWhiteCollar.Range("A2"), wsWhiteCollar.Range("A" & Rows.Count).End(xlUp))
For x = 2 To EndWC Step 1
wssheet1.Activate
wssheet1.Range("B" & x).Select
If c.Value = wssheet1.Range("B" & x).Value Then
wssheet1.Range("BC" & x).FormatConditions.Delete
wssheet1.Range("BC" & x).FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND(COUNTIF(Ratecard!Q:Q,BC3)=0,AN3>0) = TRUE"
wssheet1.Range("BC" & x).FormatConditions(1).SetFirstPriority
With wssheet1.Range("BC" & x).FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
wssheet1.Range("BC" & x).FormatConditions(1).StopIfTrue = False
wssheet1.Range("BC" & x).FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND(COUNTIFS(White Collar!A:A,B3, White Collar!U:U,BC3)=0, AV3=0) = TRUE"
With wssheet1.Range("BC" & x).FormatConditions(2).Interior
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
End With
Exit For
ElseIf Selection.Interior.ThemeColor <> xlThemeColorAccent2 Then
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
wsWhiteCollar.Activate
Next x
Next c
'Application.ScreenUpdating = True
'wssheet1.Range("B2").Select
End Sub
答案 0 :(得分:0)
将公式COUNTIF(Ratecard!Q:Q,BC3)放入新单元格中,然后在条件格式中引用该单元格。