+ Reply to Thread
Results 1 to 7 of 7

Unable to get range variable to work in Vlookup formula

  1. #1
    Registered User
    Join Date
    01-04-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    12

    Unable to get range variable to work in Vlookup formula

    Hello, my goal is to write a macro that will do a Vlookup on indefinite interval, for both data tested and range of Vlookup. When I run my Macro it selects the range, but it doesn't use it in Vlookup, so it returns me #Name error. Also I bet there is other ways to do that I'm trying to apply this to more complex problems, so I want to keep it as simple as possible.

    Here is my Code so far:
    Please Login or Register  to view this content.
    I was thinking maybe If I dim rg as something else but range it might work, Also I've tried just putting rg same problem, any help is appreciated.

    Thank you
    Last edited by ZmeY; 01-04-2012 at 11:34 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Unable to get range variable to work in Vlookup formula

    Hello ZmeY,

    Welcome to the Forum!

    The problem with the formula is it expects a cell address (string) and not the cell (range object). The code below will add the relative address of the selection into the formula.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    01-04-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Unable to get range variable to work in Vlookup formula

    Hey Leith, Thank you for your warm welcome. However I've tried the code and it returns same error #Name?. I looked at code in excel and it shows range as 'A1':'B26' (which is my current range) But these semi quotation mess it up. Any other ideas? Appreciate your help.

    Thank you

    ZmeY

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Unable to get range variable to work in Vlookup formula

    Hello ZmeY,

    The formula shows the address in single quotes? Unless this is some strange feature of Excel 2010 I don't know about, I have no explanation for that. Can you post the workbook for review?

  5. #5
    Registered User
    Join Date
    01-04-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Unable to get range variable to work in Vlookup formula

    Hey sure, I believe I've uploaded the file, Just so you know I have 2 other macros there which I use as reference they shouldn't be working properly so skip over those. The one I am testing is Ctrl + Shift + J. Thank you
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Unable to get range variable to work in Vlookup formula

    Hello ZmeY,

    I feel like an idiot. Your formula is using R1C1 referencing. The address being added is an A1 reference. The two styles can not be used in the together in the same formula. Here is the working code.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-04-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Unable to get range variable to work in Vlookup formula

    Thank you, Worked like a charm. Very helpful, thank you very much

+ 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