gpt4 book ai didi

vba - "Unable to get the VLookup property of the WorksheetFunction Class"错误

转载 作者:行者123 更新时间:2023-12-01 17:33:40 26 4
gpt4 key购买 nike

我正在尝试开发一个表单来跟踪收到的发票。该表单将有一个组合框,我可以在其中单击并选择供应商编号。我希望文本框根据从组合框中选择的供应商编号自动填充。这是我到目前为止所拥有的:

Private Sub ComboBox1_Change()    
'Vlookup when ComboBox1 is filled
Me.TextBox1.Value = Application.WorksheetFunction.VLookup( _
Me.ComboBox1.Value, Worksheets("Sheet3").Range("Names"), 2, False)
End Sub

工作表 3 从中提取信息(供应商编号和名称)。

当我返回表单测试代码时,出现以下错误:

Run-time error '1004': Unable to get the VLookup property of the WorksheetFunction class

如何解决这个问题?

最佳答案

尝试下面的代码

我建议在使用vlookup时使用错误处理程序,因为当找不到lookup_value时可能会发生错误。

Private Sub ComboBox1_Change()


On Error Resume Next
Ret = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, Worksheets("Sheet3").Range("Names"), 2, False)
On Error GoTo 0

If Ret <> "" Then MsgBox Ret


End Sub

或者

 On Error Resume Next

Result = Application.VLookup(Me.ComboBox1.Value, Worksheets("Sheet3").Range("Names"), 2, False)

If Result = "Error 2042" Then
'nothing found
ElseIf cell <> Result Then
MsgBox cell.Value
End If

On Error GoTo 0

关于vba - "Unable to get the VLookup property of the WorksheetFunction Class"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19280477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com