簡體   English   中英

Excel VBA運行時錯誤13類型不匹配

[英]Excel VBA Run-time error 13 Type mismatch

在編譯期間出現運行時錯誤13。 這是拋出的線

錯誤,y = Application.counta((“ A:A”)<>“”-3)。 我試圖將y聲明為variant /()也沒有幫助。 誰能指出我在哪里犯錯,那將非常有幫助。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM