PDA

View Full Version : Vlookup result into a textbox - Help!!



vtron
02-26-2009, 01:33 PM
Hi,

I have a combobox and a text box... I want to vlookup the selected item in the combobox from a defined range(TR) and populate the textbox with the result .. I have used the below codes to no avail and nothing is populted

1)TextBox1.Value = WorksheetFunction.VLookup(ComboBox2.Value, Range("TR"), 2, False)..

2)TextBox1.Value = WorksheetFunction.VLookup(CLng(ComboBox2.Value), Range("TR"), 2, False)

Please help.
Thank you.

Bob Phillips
02-26-2009, 01:40 PM
That looks okayish, but it is difficult to be precise as we get so little.

What is the data involved, and where is that code, which procedure?

mdmackillop
02-26-2009, 03:20 PM
If combobox data is numeric try

TextBox1.Value = WorksheetFunction.VLookup(ComboBox2.Value * 1, Range("TR"), 2, False)

vtron
02-27-2009, 02:32 AM
sorry i'll be a bit clearer...
I have 2 comboboxes and a text box...I have set the rowsource of the combobox1 to a1:a8 (these contain words, interestingly i had to use the index values as opposed to the actual words in the code for the code to work..i still dont know why?)...based on the selection of cmbx1 ..data is filled into cmbbox2.. i used the below code..

Public Sub ComboBox1_Change()

If ComboBox1.Value = 0 Then
ComboBox2.RowSource = "Headings!B2:B30"
ElseIf ComboBox1.Value = 1 Then
ComboBox2.RowSource = "Headings!c2:c30"
ElseIf ComboBox1.Value = 2 Then
ComboBox2.RowSource = "Headings!d2:d30"
ElseIf ComboBox1.Value = 3 Then
ComboBox2.RowSource = "Headings!e2:e30"
ElseIf ComboBox1.Value = 4 Then
ComboBox2.RowSource = "Headings!f2:f30"
ElseIf ComboBox1.Value = 5 Then
ComboBox2.RowSource = "Headings!g2:g30"
ElseIf ComboBox1.Value = 6 Then
ComboBox2.RowSource = "Headings!h2:h30"
ElseIf ComboBox1.Value = 7 Then
ComboBox2.RowSource = "Headings!i2:i30"
Else
End If

End Sub

and then i want to vlookup the comboxbox2 selecttion againstt a range (TR) and then populate the result into the textbox2..

i used the below code and it does not work.

Public Sub TextBox1_Change()

TextBox1.Value = WorksheetFunction.VLookup(ComboBox2.Value, Range("TR"), 2, False)

End Sub
Appreciate the help..thks