1

我在编译期间收到运行时错误 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
4

1 回答 1

2

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

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

于 2013-06-20T03:49:35.643 回答