1

I have a userform with 1 combobox and 3 textboxes. I want to use vlookup to display the values in the texboxes based on the selection in the combobox. The first textbox works but after that it gives errors. Pls help. Here is my code:

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
  • 2
    this part Application.VLookup(ComboBox1.Value, Range("A1:B17"), 3, 0) returns an error, since you want to return the 3rd column, when you defined the range with only 2 columns (` Range("A1:B17")`) Commented Jul 27, 2017 at 7:06
  • Also, you have typing error: TextBox2.alue = Platform - you missed 'V' in Value. Commented Jul 27, 2017 at 7:17
  • Please do some basic error checking before posting a question here. Your problem arises simply because you have typos in your code. Voting to close this question as low quality. Commented Jul 27, 2017 at 7:23

1 Answer 1

1

As mentioned in the comments when you refer to 3. column, you should have at least 3 columns in your range. Read more about VLookup here.

Try like this:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.