Excel VBA运行时错误13types不匹配

在编译期间,我得到一个运行时错误13。 这是抛出一个

错误,y = Application.counta((“A:A”)<>“” – 3)。 我试图声明y作为变种/()也没有帮助。 任何人都可以请指出我犯了一个错误,这将是非常有益的。

Option Explicit Sub Test() ' z= no of rows(temp calc sheet emp id) ' x= no of columns(dashboard calender) ' y= no of rows(dashboard emp id) Dim i, j, k, d, x, y, z As Long Dim Empid As Long Dim currentdate, startdate, enddate As Date 'Dim countA As Long startdate = Worksheets("Temp calc").Range("C2") enddate = Worksheets("Temp calc").Range("D2") x = (Range("n2") - Range("n1")) y = Application.counta(("A:A") <> "" - 3) z = Worksheets("Temp Calc").counta(("A:A") - 1) For i = 1 To y 'To loop through the emp_id in dashboard. For j = 1 To x Step 1 'To loop through the calender in dashboard daywise. For k = 1 To z 'To loop through the emp_id i temp calc sheet. d = 0 Empid = Cells(4, i) currentdate = Cells(3, 17 + j) If (Cells(k, 1)) = Empid Then If (currentdate > startdate) & (currentdate < enddate) Then 'To check whether the first column date falls within the project start and end date d = d + 1 startdate = startdate + 1 enddate = enddate + 1 Cells(i + 3, j + 16) = d End If End If Next Next Next End Sub 

如果要计算A列中的非空白单元格,并从此数字中减去3,请尝试:

y = Application.WorksheetFunction.CountA(Range("A:A")) - 3