我有如下代码。当我运行代码时,它被认为是相等的,并且将挂起。
For n1 = 4 To lrow
If wk1.Cells(n1, 3) <> "KA Special" Or wk1.Cells(n1, 3) <> "KA 1" Or wk1.Cells(n1, 3) <> "KA 2" Or wk1.Cells(n1, 3) <> "KA 3" Or wk1.Cells(n1, 3) <> "GOA" Or wk1.Cells(n1, 3) <> "Jharkhand" Or wk1.Cells(n1, 3) <> "Bihar" Or wk1.Cells(n1, 3) <> "WB" Or wk1.Cells(n1, 3) <> "NB" Or wk1.Cells(n1, 3) <> "NE1" Or wk1.Cells(n1, 3) <> "NE2" Or wk1.Cells(n1, 3) <> "SK" Then
With wk2
.Range("cd2:cd" & lrow).AutoFilter field:=82, Criteria1:=">=" & st1, Operator:=xlAnd, Criteria2:="<=" & en1
wk1.Cells(n1, 11) = Application.WorksheetFunction.SumIfs(wk2.Range("BU:BU"), wk2.Range("BJ:BJ"), "=" & wk1.Range("c" & i), wk2.Range("CD:CD"), ">=" & st1, wk2.Range("CD:CD"), "<=" & en1, wk2.Range("BM:BM"), "TT/INST")
End With
End If
Next n1
答案 0 :(得分:1)
一定要意识到您的IF语句将始终为True。
如果您有两个NOT语句或在一起,则其中之一必须至少为True。