我正在尝试使用双重标准设置一个简单的计数器,我被
拦截运行时错误13
正如你看到的那样,我有多个计数器,全部都是整数,我希望它们根据列D和A的值来计算每个被锁定的命中。)如果重要:D列中的文本是通过Dates-comparisson在另外两列中生成,但格式化为文本)。
Private Sub Workbook_Open()
Dim lr, i, k, a, b, c, d, e, f, g, h, j, l, m, n, o, p, q, r, s As Integer
a = b = c = d = e = f = g = h = j = l = m = n = o = p = q = r = 0
Worksheets("overdue").Activate
lr = Range("D" & Rows.Count).End(xlUp).Row
k = 1
For i = 1 To lr
If Cells(i, "D").Value = "OVERDUE" And Cells(i, "A") Like "*φίλτρου*" Then
a = a + 1
ElseIf Cells(i, "D").Value = "OVERDUE" And Cells(i, "A") Like "*Λιπαντικού*" Then
b = b + 1
k = k + 1
End If
Next i
我甚至尝试在像
这样的单元格语法中重新定位Worksheet-nameIf Worksheets("overdue").Cells(i, "D").Value = "OVERDUE" And Worksheets("overdue").Cells(i, "A") Like "*ößëôñïõ*" Then
但它似乎没有帮助。有人有建议吗? 我忘了添加,调试器显示If开始的行,所以第一个计数器的语句。
另外,我知道,如果我彻底改变代码并尽可能地简化它,就像这样
Sub testcounter()
Dim cell As Range
Dim a As Integer
For Each cell In Worksheets("Sheet2").Range("D1:D3500")
If cell.Value = "1" Then
a = a + 1
End If
Next
MsgBox a
End Sub
它仍然给出了
错误13
在IF声明的第一行。
答案 0 :(得分:4)
除s
之外的所有变量都不是Integer
s。
所有变量(Integer
s)都会自动初始化为零。
a = b = c = d = e = f = g = h = j = l = m = n = o = p = q = r = 0
显示逻辑比较,即检查r是否等于0,然后将此比较的结果与q
进行比较,等等。
答案 1 :(得分:4)
Dim a, b, c, d As Integer '<< only d is integer...
a = b = c = d = 0
Debug.Print "a", a
Debug.Print "b", b
Debug.Print "c", c
Debug.Print "d", d
输出:
a True
b
c
d 0