簡體   English   中英

Excel VBA:無法獲取工作表函數類的匹配屬性運行時錯誤 1004

[英]Excel VBA: unable to get the match property of the worksheetfunction class Run-time error 1004

我有以下代碼,但出現錯誤:“無法獲取工作表函數類的匹配屬性”

誰能幫我?

Sub ASub()
    'This part is for the Fully Dynamic and Dependent Combobox Client ID and Account Nr.
    'Client ID Part
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Clients")
Dim i As Integer

Me.cbox_clientID.Clear
    For i = 2 To Application.CountA(sh.Range("1:1"))
        Me.cbox_clientID.AddItem sh.Cells(1, i).Value
    Next i
End Sub

使用“WorksheetFunction.CounA”但“Application.CountA”。 使用第一個。

貌似沒有貼出完整的代碼。 我有一個包含帳戶編號的列表。 如果我選擇一個,然后我開始刪除帳戶 nr 代碼給我帶來上述錯誤消息。 因為沒有與擴孔帳戶 nr 匹配。

'Order Input Date Format Order Date
Private Sub UserForm_Activate()

'This part is for the Fully Dynamic and Dependent Combobox Client ID and Account Nr.
'Client ID Part

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Clients")
Dim i As Integer

Me.cbox_clientID.Clear

For i = 2 To Application.CountA(sh.Range("1:1"))
    Me.cbox_clientID.AddItem sh.Cells(1, i).Value
Next i

End Sub

'This part is for the Fully Dynamic and Dependent Combobox Client ID and Account Nr.
'Account Part
Private Sub cbox_clientID_Change()

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Clients")

Dim i, n As Integer
Me.cbox_account.Clear

n = Application.WorksheetFunction.Match(Me.cbox_clientID.Value, sh.Range("1:1"), 0)

For i = 2 To Application.WorksheetFunction.CountA(sh.Cells(1, n).EntireColumn)
    Me.cbox_account.AddItem sh.Cells(i, n).Value

Next i

Me.cbox_account.ListRows = 20

End Sub

我只是修復了以下適用於我的案例。

'Match Error
On Error Resume Next

暫無
暫無

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

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