+ Reply to Thread
Results 1 to 4 of 4

Macro to drag vlookup across columns and rows

  1. #1
    Registered User
    Join Date
    07-04-2012
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    2

    Macro to drag vlookup across columns and rows

    I'm fairly new to using Excel beyond it's basic functions and I am trying to do VLookups for a huge sheet. Problem is I need to drag the formula in both the rows and columns because the data is collected over many years. My spreadsheet is set up somewhat like this. All data/sheet names/etc are arbitrary.

    A B C D
    1 Ticker Company Jan Feb
    2 MCD McDonalds 5 7
    3 XYZ XYZ 12 15



    C2 would have the formula =VLOOKUP(A2, DATA!$B$1:$Z$300,COLUMN(DATA!C:C),FALSE)

    Then drag that forumla down Column C.

    I then need to change the lookup_value in C2 to $C$2 so I can drag the formula across from C2 to W2 (so the lookup value doesnt change when I drag). Then repeat this process for C3, C4, C5, etc.

    Instead of manually editing, can I record a macro to do this for me? Or, is there a simpler way to do it all together?
    Last edited by baryons; 07-04-2012 at 02:35 AM.

  2. #2
    Administrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to drag vlookup across columns and rows

    I would think you want to LOCK the column with a $ symbol but not lock the row.

    =VLOOKUP($A2, DATA!$B$1:$Z$300,COLUMN(DATA!C:C),FALSE)

    Try that in C2, then copy to the right and down as desired.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    07-04-2012
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Macro to drag vlookup across columns and rows

    Quote Originally Posted by JBeaucaire View Post
    I would think you want to LOCK the column with a $ symbol but not lock the row.

    =VLOOKUP($A2, DATA!$B$1:$Z$300,COLUMN(DATA!C:C),FALSE)

    Try that in C2, then copy to the right and down as desired.
    Yes! That was such a quick fix. Thank you so much!!

  4. #4
    Administrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to drag vlookup across columns and rows

    If that takes care of your need, please select Thread Tools from menu above and set this topic to SOLVED.

+ 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