Userfrm Lookup Works For text not Number
Many thanks Tom your code works perfectly. Unfortunately I now have another
small problem...The number I am looking up for a reference to a row on my
worksheet........ [(ComboBox1.Text), _ Worksheets("Blending Details")]...
can be listed more than once. So in text box2 I want to refer to the first
occurrence of the ComboBox1.Text then in text box3 I want to refer to the
second occurrence of the ComboBox1.Text (if there is one) and so on and so
on. Sounds real complicated but my sheet is like a record of order details
so each record has an order number (the number I am looking up) but many
records can have the same order number as they are individual components of
the same order. I hope your not confused after that lot ( I know I am).
Thanks Again
gregork
"Tom Ogilvy" wrote in message
...
Because you are looking up a string and not a number
Private Sub ComboBox1_Click()
if not isnumeric(ComboBox1.Text) then
TextBox2.Text = Application.VLookup(ComboBox1.Text, _
Worksheets("Blending Details").Range("A2:Z500"), 2, False)
Else
TextBox2.Text = Application.VLookup(cdbl(ComboBox1.Text), _
Worksheets("Blending Details").Range("A2:Z500"), 2, False)
End If
End Sub
Adjust to suit your situation, but if your lookup range contains numbers,
then lookup with a Number for best results (given you are looking for a
number).
--
Regards,
Tom Ogilvy
"gregork" wrote in message
...
Hi,
I have the following code for inserting data on a user form based on a
number on a cell in a worksheet:
Private Sub ComboBox1_Click()
TextBox2.Text = WorksheetFunction.VLookup(ComboBox1.Text,
Worksheets("Blending Details").Range("A2:Z500"), 2, False)
End Sub
When I put a word in the combo box the lookup is successful and I get
the
value returned in textbox2. But when a number is in the combox I get a
runtime error.
Any ideas?
Thanks
gregork
|