Excel VBA:无法获取工作表函数类的匹配属性运行时错误1004

时间:2019-03-05 14:06:33

标签: excel vba

我有以下代码,但出现错误:“无法获取worksheetfunction类的match属性”

有人可以帮助我吗?

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

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

好像没有发布完整的代码。我有一个帐号为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

答案 2 :(得分:0)

我只是固定为以下情况进行工作。

'Match Error
On Error Resume Next