VLookup error in the Userform

S Nik

New Member
Joined
Jan 25, 2018
Messages
10
I created an inventory worksheet with userforms. Now I have a problem with VLookup command. I want the name of the item is shown in the "txtName" after I scanned the barcode in the "txt2DBarcode."

Everything looks fine till I send the information. Then I receive an error.
Run-time error '1004': Unable to get the VLookup property of the worksheetFunction class.

HTML:
Private Sub txt2DBarcode_A_afterupdate()      
    If WorksheetFunction.CountIf(Sheet1.Range("A:A"), Left(Me.txt2DBarcode_A.Text, 16)) = 0 Then
        MsgBox "This is an incorrect Barcode!"
        Me.txt2DBarcode_A.Value = ""
    Exit Sub
    End If
    
    With Me
    .txtName = Application.WorksheetFunction.VLookup(Left(txt2DBarcode_A.Text, 16), Sheet1.Range("Vac_List"), 2, 0)
    End With
 End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Yes. I wish I could send a screenshot. The first 16 digit of "txt2DBarcode" is my item id that is listed on sheet1 range A:A.
 
Upvote 0
Try:

Code:
.txtName = Application.WorksheetFunction.VLookup(Val(Left(txt2DBarcode_A.Text, 16)), Sheet1.Range("Vac_List"), 2, 0)
 
Upvote 0
Ok lets break it down. Run these lines just before your line thats failing:

Code:
msgbox Val(Left(txt2DBarcode_A.Text, 16))
msgbox Sheet1.Name
msgbox Range("Vac_List").parent.name
msgbox Range("Vac_List").address

Paste the results
 
Upvote 0
Ok lets break it down. Run these lines just before your line thats failing:

Code:
msgbox Val(Left(txt2DBarcode_A.Text, 16))
msgbox Sheet1.Name
msgbox Range("Vac_List").parent.name
msgbox Range("Vac_List").address

Paste the results
It is showing me 3 message boxes with the same error at the end.
 
Upvote 0
So in sheet "Vac_List" you have a named range "Vac_List". What is the address of this named range? Does it have your lookup value from txt2DBarcode in the first column of this range?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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