+ Reply to Thread
Results 1 to 10 of 10

VBA VLookup Error 1004

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    11

    VBA VLookup Error 1004

    Hi All,

    Im trying to create a userform in VBA in which I can manually enter a number in a textbox which then will search for the corresponding data in a different sheet.

    Please Login or Register  to view this content.
    When I try this, I get error 1004; "The properties of Vlookup of WoksheetFunction cannot be executed".

    What am I doing wrong and how to fix this?

    Thanks in advanced!!
    Last edited by Ronny66; 05-17-2013 at 07:19 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: VBA VLookup Error 1004

    Hi
    When it finds the corresponding data in a different worksheet what do you want to do and also which sheet do you want to search in?
    Tony

  3. #3
    Registered User
    Join Date
    05-17-2013
    Location
    Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: VBA VLookup Error 1004

    When it finds the corresponding data; the exact same Number as I entered, I want it to show the corresponding costumer information such as name and adress.
    This can be done by the last line in the code.

    I want it to search in sheet4, as defined in the code.

    Thanks for the reply!

  4. #4
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: VBA VLookup Error 1004

    Hi Ronny
    Looking at your code you are searching in columns A to Z but you are only returning the value in Column 2 of the search range if the value in VLOOKUP is found. On that basis you only need to search between columns A and B. This may be why you are getting the error.
    Hope this helps.
    Good luck.
    Tony

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    Are the values in A2:A18 on Sheet4 numeric or text?

    If they are numeric then you need to convert the text value from the textbox to numeric.

    To do that you can try some of VBA's conversion functions like Val, CInt, CDbl etc
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    05-17-2013
    Location
    Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: VBA VLookup Error 1004

    Quote Originally Posted by Norie View Post
    Are the values in A2:A18 on Sheet4 numeric or text?

    If they are numeric then you need to convert the text value from the textbox to numeric.

    To do that you can try some of VBA's conversion functions like Val, CInt, CDbl etc

    The values in A2:A18 are numeric and only numeric, just as the value I enter in the textbox. The corresponding data from B2:C18 is not numerical.

    I've looked up the conversion functions but I can't really understand how to implement them in the code. Could you help me with that?



    Hi Ronny
    Looking at your code you are searching in columns A to Z but you are only returning the value in Column 2 of the search range if the value in VLOOKUP is found. On that basis you only need to search between columns A and B. This may be why you are getting the error.
    Hope this helps.
    Good luck.
    Tony
    Unfortunately this did not help

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

    Re: VBA VLookup Error 1004

    The values in the textbox are not numeric, they are text.

    Give this a shot.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-17-2013
    Location
    Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: VBA VLookup Error 1004

    That does seem to work as long as the value I use in the sheet where it has to search from only has a single digit.

    The values I need to use have 5 digits.

    Thanks for the help!

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

    Re: VBA VLookup Error 1004

    If you are still having problem it might be an idea to attach a sample workbook.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  10. #10
    Registered User
    Join Date
    05-17-2013
    Location
    Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: VBA VLookup Error 1004

    Hi Guys,

    A bit late, but better late than never.

    I finally managed to fix the problem by adding a second step to the process; having a VLookUP in the worksheet do the work.
    Lucky coincidence; this extra step adds more flexibility to the worksheet as several other worksheets can read from it too.

    Thank you guys for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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