+ Reply to Thread
Results 1 to 4 of 4

Error passing a range to the vlookup function

  1. #1
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Error passing a range to the vlookup function

    Hi,

    I'm trying to pass a range to the worksheetfunction.vlookup method and I can't seem to get it to work. The code I have is below and I've inserted a comment where the error I get occurs.

    Please Login or Register  to view this content.
    When I try to run this it stops at
    Please Login or Register  to view this content.
    with the error "Runtime Error 1004 - Method 'Range' of object '_Global' failed."

    Any suggestions on how I might remedy this would be most appreciated!

    Kindest Regards,
    Tim

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Error passing a range to the vlookup function

    There's no need to select anything here (nor almost ever in VBA). You get drowned in to many redundant variables..

    Please Login or Register  to view this content.



  3. #3
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Error passing a range to the vlookup function

    snb,

    Many thanks for the speedy response - the code is much more concise without all of the select lines.

    When I run the code, I get a Run Time Error 13, Type Mismatch. Hovering over the selected code where the runtime error occurs, it seems like the vlookup is looking up the correct Arg1 value and it's looking at the correct sheet for Arg2. The Arguments 3 and 4 are correct. Could my syntax of the range for arg2 be incorrect?

    Kindest Regards,
    Tim

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Error passing a range to the vlookup function

    use F8 in the VBEditor to debug.

    use the local variables window to see the variables' values.

    this will suffice:
    Please Login or Register  to view this content.
    Last edited by snb; 08-21-2011 at 02:49 PM.

+ 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