我正在尝试使用多个 AND 参数在 VBA 中实现 CountIf UDF。我构建了以下代码,它给了我一个app-defined or obj error
.
Sub Count_PoA()
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row - 5
End With
For i = 6 To LastRow
Count = 0
For j = 17 To 58
For k = 12 To 397 Step 13
If Sheet9.Range("JA:KD & i") = Sheet2.Cells(1, j) And Sheet4.Cells(i, k) = "TRUE" And Sheet4.Cells(i + 4, k) = "TRUE" Then
Count = Count + 1
End If
Count = Sheet2.Range("B" & j)
Next
Next
Next
End Sub
理想情况下,我想要相当于:
COUNIF(Dim someRange as Range, condition1, condition2, condtion3, ...)
其中 condition1 可以是一个值或表达式,并且所有条件都在 AND 条件中连接在一起
例子:
COUNTIF(Range("JA:KD & i"), Sheet2.Cells(j,1) And Sheet4.Cells(i, k) = "TRUE" And Sheet4.Cells(i + 4, k) = "TRUE")