VBLookup on Combobox1 - ERROR

Bryan123

New Member
Joined
May 23, 2019
Messages
41
Hi,

In need of your help. Cant seem to move forward on this problem. I have a combobox with a list of emp ID's, when I choose one from the list, it should populate an info to the textbox(workstream) but to no avail. Alwas goes to the error "not found". Please see attached

Private Sub Combobox1_Change()
Dim rng as range
set rng = worksheets("LRS sampling").range("A2:L200")
On Error Resume Next
workstream.value = application.worksheetfunction.vlookup(combobox1,Rng,3,False)
If Err.Number <> 0 Then workstream.value = "not found"
THanks

Bryan
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi & welcome to MrExcel.
What are your emp ID's?
 
Upvote 0
Welcome to the forum.

Are your IDs numeric? If so, you should convert to number before doing the lookup. Also if you use Application.Vlookup, you can trap an error value rather than a runtime error:

Code:
Private Sub Combobox1_Change()
Dim rng as range
set rng = worksheets("LRS sampling").range("A2:L200")
dim theValue
theValue = application.vlookup(clng(combobox1),Rng,3,False)
If iserror(thevalue) then
 workstream.value = "not found"
else
workstream.value = thevalue
end if
 
Upvote 0
Hi.. EMP IDS should be from a column in excel

Private Sub UserForm_Initialize()

employee = Worksheets("LRS sampling").Range("A2:L200").Value
Dim ListItems As Variant, i As Integer
With Me.ComboBox1
.Clear
Application.ScreenUpdating = False
ListItems = employee
For i = 1 To UBound(ListItems, 1)
.AddItem ListItems(i, 10)
Next i
ComboBox1.ListIndex = 0
End With

End Sub
 
Upvote 0
It looks like the IDs are in column J of your worksheet, but you're attempting to look them up in column A.
 
Upvote 0
Hi Rory, yes you're right. The IDS are in column J.. Please let me know what I did wrong on the code.. Thank you
 
Upvote 0
Make this change
Code:
   Set rng = Worksheets("LRS sampling").Range("[COLOR=#ff0000]J2[/COLOR]:L200")
 
Upvote 0
Which column do you want values back from - C or L? If it's L use fluff’s suggestion.
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,322
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top