+ Reply to Thread
Results 1 to 3 of 3

Excel macro vlookup

  1. #1
    Registered User
    Join Date
    01-11-2014
    Location
    singapore
    MS-Off Ver
    Excel 2010
    Posts
    41

    Excel macro vlookup

    Hi,

    I have an excel where i want to lookup column header "Country" and vlookup the row to find if it's United States, Europe or Asia from a reference sheet. As the Country header might not always be on the same column from the spreadsheet i received from user. It might be in Column B today and Column Z the next day. So i have a macro that search for this header name. That works fine until the vlookup statement which fails with runtime error.

    i = lastCol - ColCtry --->(i got the answer as -20)

    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[i],'Sheet1'!RC[-3]:RC[-4],2,0)"


    The error lies with this code: VLOOKUP(RC[i]
    It does not recognise "i". Macro will works if i directly enter it as -20

    Need help to advise what is wrong with my code.

    Thanks

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Excel macro vlookup

    Anything between the quotes is a literal. Because I is a variable, the interpreter is trying to insert the value, but throws the error.

    You have to move the variable outside the quotes.

    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Excel macro vlookup

    Nevermind...

+ 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. lookup value for a vlookup formula in VBA for an excel macro
    By nskrbin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2013, 05:32 PM
  2. [SOLVED] VLookup error in Excel 2011 for Mac Macro
    By zuck in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-20-2013, 04:34 PM
  3. Adding vlookup value in excel recorded macro
    By peednaswan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-17-2012, 03:57 AM
  4. Excel Macro (vlookup)?
    By mcguire1019 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-09-2012, 05:57 PM
  5. Turn an Excel Vlookup Formula into a Macro
    By Steve Strunk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2011, 12:27 PM
  6. Run Vlookup with UserForm Excel Macro
    By herukuncahyono in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2009, 03:59 AM
  7. Using Macro to Run Vlookup+Excel 2007
    By Sumku in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2009, 04:55 PM
  8. Applying Vlookup using a Macro(Vlookup+Macro) in Excel 2007
    By Sumku in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-03-2009, 08:58 PM

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