+ Reply to Thread
Results 1 to 12 of 12

VBA Vlookup not returning values

  1. #1
    Registered User
    Join Date
    01-02-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2007
    Posts
    5

    VBA Vlookup not returning values

    Hi all,

    I have nto written macros for some years and so am having to grasp things again. I have a vlookup which searches for a number obtained from a text file input using mid and search functions. It looks up in a range within another sheet. these are numbers.

    I keep getting error 2042 when i have tested values that are true and false. I have also converted the data type of the string look up to be Lng nut still it fails.

    I have also tried to use worksheetfunction but it did not work. I have also tried using .value on the end.

    The vba is below.

    Any help would be greatly appreciated.

    Thanks,
    Rich


    Please Login or Register  to view this content.
    Last edited by zbor; 01-09-2013 at 10:27 AM.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: VBA Vlookup not returning values

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  3. #3
    Registered User
    Join Date
    01-02-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: VBA Vlookup not returning values

    Hi Zbor, apologies for that. Here you go.

    Please Login or Register  to view this content.

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: VBA Vlookup not returning values

    it's enough to edit your original post (I will do that now for you).

  5. #5
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA Vlookup not returning values

    Hi Richard,

    setting the Nrange range could be written as

    Please Login or Register  to view this content.
    the vlookup statement contains a typing error, but could also be re-written as

    Please Login or Register  to view this content.
    or alternatively (no need for Nrange)

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA Vlookup not returning values

    Hi Richard,

    setting the Nrange range could be written as

    Please Login or Register  to view this content.
    the vlookup statement contains a typing error, but could also be re-written as

    Please Login or Register  to view this content.
    or alternatively (no need for Nrange)

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-02-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: VBA Vlookup not returning values

    Many thanks for your response Ollie B.
    * I have tried the solution but it still doesn't find the value.*
    Shall I upload the data sheets too?**

    Many thanks,
    Rich

  8. #8
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA Vlookup not returning values

    Sure, why not. I will have a look for you

  9. #9
    Registered User
    Join Date
    01-02-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: VBA Vlookup not returning values

    Many thans for that Ollie. Sorry for the delay in responding, I have some problems responding when I am in work; for some reason the page eeps timing out.

    I have attached the excel.

    Many thanks in adavnce,
    Rich
    Attached Files Attached Files

  10. #10
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA Vlookup not returning values

    Richard,

    With all respect, the code could do with some cleaning up, but then again that is just my opinion

    To get it all to work:
    - remove the Match instruction using the Nrange object (delete the statement),
    - and change the Match instruction using the column(2) to:

    Please Login or Register  to view this content.
    i.e. I added the Val(...) instruction to make sure the numeric value is used for the search

  11. #11
    Registered User
    Join Date
    01-02-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: VBA Vlookup not returning values

    Ollie B,
    Many thanks , It is much appreciated. Yes I will tidy it up. I've not used vba for about5 years and hence it is clunky. Any pointers are greatly received.

    Rich

  12. #12
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA Vlookup not returning values

    Richard,

    I think the code below does pretty much the same as your code. Just for fun

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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