Excel VBA 使用 vlookup 的用户表单

Excel VBA Userform using vlookup

我有一个带有 1 个组合框和 3 个文本框的用户表单。我想使用 vlookup 根据组合框中的选择显示文本框中的值。第一个文本框有效,但之后出现错误。请帮助。 这是我的代码:

Private Sub ComboBox1_Change()
    Description = Application.VLookup(ComboBox1.Value, Range("A1:B17"), 2, 0)
    TextBox1.Value = Description
    Platform = Application.VLookup(ComboBox1.Value, Range("A1:B17"), 3, 0)
    TextBox2.alue = Platform
End Sub   

正如您在提到 3. 列时的评论中提到的,您的范围内至少应有 3 列。 Read more about VLookup here.

这样试试:

Private Sub ComboBox1_Change()

    Description = Application.VLookup(ComboBox1.value, Range("A1:C17"), 2, 0)
    TextBox1.value = Description
    Platform = Application.VLookup(ComboBox1.value, Range("A1:C17"), 3, 0)
    TextBox2.value = Platform

End Sub