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
 
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?

In sheet1 I have "Vac_List" name range that its column A is code (16 digit number) and column B is the item name. I want to see item name in my userform, if first 16 digit of barcode is same as column A.

Sorry if it is confusing.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Yes i know what you are after but i cant see your workbook so im trying to single out the error. Tell me the address of the named range.
 
Upvote 0
In fact I have a worksheet and range name as "Vac_List." Do you think that causes the problem?
 
Upvote 0
So the error is saying it cant find the lookup value in A3:A20. When dealing with numbers as lookup values you have to be certain you are comparing like with like ie true numbers in the lookup value and lookup array not text numbers
 
Upvote 0
You said it was in Sheet1 just? Tell you what you could do. Go to a completely new sheet and type out a VLOOKUP formula that works using the barcode and the named range. Copy it and paste it here.
 
Upvote 0
Please don't cross-post without providing a link to the thread on the other forum.
 
Upvote 0
Upvote 0
S Nik

They are not the same, that's kind of the point.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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