+ Reply to Thread
Results 1 to 23 of 23

VLookup error in the Userform

  1. #1
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    VLookup error in the Userform

    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."

    The second part of the code is working and can find the name of the item. But if the barcode number does not exist in the Sheet1.Range "A:A" I have debug error instead of showing the message.

    Here is the code:

    HTML Code: 
    Untitled.jpg

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VLookup error in the Userform

    Please Login or Register  to view this content.
    oughta be
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    Yeyyyyy. It is working. Thank you Josie.

  4. #4
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,256

    Re: VLookup error in the Userform

    'maybe like this
    Please Login or Register  to view this content.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VLookup error in the Userform

    Will work also.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    Thank you all for your help. It is interesting that the code is working perfectly for one Userform (Received), but for the other userform in the same spreadsheet is not. The only different is "txt2DBarcode" changed to "txt2DBarcode_A".

    Run-time error '1004': Unable to get the VLookup property of the worksheetFunction class.

    HTML Code: 

  7. #7
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    I was wrong. I can see this error on my all userforms.

    Untitled1.jpg

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VLookup error in the Userform

    countif will convert your values to a number if possible (15 significant digits only) and look for that. vlookup will not convert and will look for text. if your actual data is numbers formatted to show the leading zero then that would explain it.

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,936

    Re: VLookup error in the Userform

    It may be that leading zeroes are being removed. Try adding a leading single quote to prevent autocasting of the string: Add

    "'" &

    before the Left, like:

    .... VLookup("'" & Left(txt2DBarcode.Text,16),......_
    Bernie Deitrick
    Excel MVP 2000-2010

  10. #10
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    Quote Originally Posted by Bernie Deitrick View Post
    It may be that leading zeroes are being removed. Try adding a _
    Still I have debug.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VLookup error in the Userform

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.
    If posting code please use code tags, see here.

  12. #12
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    Quote Originally Posted by JosephP View Post
    countif will convert your values to a number if possible (15 significant digits only) ...
    Thank you Josie. What is your recommendation for my code?

    Below is the screenshot of sheet1.

    Capture.JPG

  13. #13
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    Quote Originally Posted by Norie View Post
    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.
    The sample is attached. You can test "Received Vaccine" form with this barcode: 01003000648270191719081010N021719

    It must show "Varicella Varivax" as name of item. And if you change the first 16 digit number must alert. But it is not working.
    Last edited by S.Nik; 01-26-2018 at 09:36 AM.

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VLookup error in the Userform

    Why are you using Val in the VLookup?

    This worked for me.
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    Quote Originally Posted by Norie View Post
    Why are you using Val in the VLookup?

    This worked for me.
    Please Login or Register  to view this content.
    Why it is not working for me?

    Untitled.jpg

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VLookup error in the Userform

    When you get the error what code are you using?

    PS Have you considered using a combobox for the codes rather than a textbox?
    Last edited by Norie; 01-25-2018 at 05:11 PM.

  17. #17
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,936

    Re: VLookup error in the Userform

    Two mistakes - you were using Val, which would remove the leading zeroes, and your sheet name is Vac_List, but you were treating it as a range name. This works:

    Please Login or Register  to view this content.
    Capture.JPG

  18. #18
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    [QUOTE=Bernie Deitrick;4829287]Two mistakes - you were using Val, which would remove the leading zeroes, and your sheet name is Vac_List, but you were treating it as a range name. This works:

    Please Login or Register  to view this content.
    In fact I have a worksheet and range name as "Vac_List." Do you think that causes the problem?

    Thank you for the screenshot but did you try to send it too? Because after I send it and see the message that "Data added" I see error.

    Capture.JPG

  19. #19
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,936

    Re: VLookup error in the Userform

    In my experience, it is never a good idea to have two different things with the same name. In any event, your sheet has an underscore in its name, so at the least you should use

    Please Login or Register  to view this content.

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VLookup error in the Userform

    Please don't cross-post without providing a link to the thread on the other forum.

  21. #21
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    [QUOTE=Bernie Deitrick;4829310]In my experience, it is never a good idea to have two different things with the same name. In any event, your sheet has an underscore in its name, so at the least you should use

    You are right. I am new in VBA world. I thought it is less complecated if I pick a name for both. I tried your recent code and I see error after I hit save:

    Capture.JPG

  22. #22
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,936

    Re: VLookup error in the Userform

    You've re-introduced the error that we fixed before - after the code is cleared from the text box "txt2DBarcode" the txt2DBarcode_afterupdate code is run again and you are not properly handling the null string case. Try it like the code below, where if the text of that textbox is "" then nothing is done (the code only works is the value is not "").

    We had added

    Application.EnableEvents = False
    '....
    Application.EnableEvents = True

    around this section:

    'Clear the data
    txt2DBarcode_A.Value = ""

    but it is not there anymore....


    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    01-10-2018
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    31

    Re: VLookup error in the Userform

    Quote Originally Posted by Bernie Deitrick View Post
    You've re-introduced the error that we fixed before - after ...
    Thank you very much Bernie. You made my day. The code is working. You are awsome!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Unable to Get userForm to Recognise code. With Error message regarding VLookup
    By Mark Dynes in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 03-08-2017, 01:20 PM
  2. Replies: 2
    Last Post: 01-12-2017, 09:51 PM
  3. [SOLVED] userform vlookup 424 error
    By adamheon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-28-2016, 05:33 PM
  4. Error trying to import userform into Outlook: Unable to load UserForm.FRX
    By jeffclanders in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-08-2016, 12:36 PM
  5. Userform to return vlookup then reference vlookup text
    By BG1983 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-17-2016, 02:09 PM
  6. [SOLVED] Userform vlookup - error when name not in spreadsheet
    By glynnhicks in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2013, 03:33 AM
  7. UserForm, Vlookup Error when the form is done.
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-11-2010, 05:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1