Reputation:
I am trying to create a script for a invoice, that can perform a vlookup based on the entry in a userform. I have a userform, which has a combobox with a named range. I would like four text boxes, which display the result of the vlookup. I have a vlookup set up, which just goes into the normal cell in the worksheet. it is:
=VLOOKUP($A22,Products!$A$1:$B$1679,2,FALSE)
I would like it, so that rather than looking for cell A22, it performs the vlookup from the combobox, which is just named test. I would then like to repeat it for:
=VLOOKUP($A47,Products!$A$2:$A$1679,1,FALSE)
=VLOOKUP($A47,Products!$A$2:$A$1679,1,FALSE)
=VLOOKUP($A47,Products!$A$2:$C$1679,3,FALSE)
Thanks for reading, and I hope that you can help. If you could
Upvotes: 1
Views: 1678
Reputation: 53653
Refer to the combobox control's .Value
property, pseudo-code:
=VLOOKUP(UserForm1.ComboBox1.Value,Products!$A$2:$A$1679,1,FALSE)
Etc.
Actual code:
Dim lookupRange as Range
Set lookupRange = Worksheets("Products").Range("A2:A1679")
Product = Application.Vlookup(UserForm1.Selectprodcutcombo.Value, _
lookupRange, 1, False)
Of course, you will need to modify the name of your form and combobox, based on your form's design.
Upvotes: 1