+ Reply to Thread
Results 1 to 3 of 3

Macro Insert Vlookup Formula

  1. #1
    Registered User
    Join Date
    06-15-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    23

    Macro Insert Vlookup Formula

    I am trying to create a macro to insert a vlookup formula into a column of a report. There are two things I am unsure of though. 1. I would like formula to look in the sheet based off a value in column A. 2. I am not sure how to have some cells relative and some absolute within the macro.

    In my example:
    A1 = 123456
    A2 = 987654

    F1 = vlookup(E1,'123456'!,$I$1:$J$1000,2,False)
    F2 = vlookup(E1,'987654'!,$I$1:$J$1000,2,False)

    Note that the formula looks up the Sheet (123456 or 987654) based on the value in column A.

    Thanks for your help.

  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: Macro Insert Vlookup Formula

    Hello smmeader,

    Are you copying from column "A" to column "F" on the same worksheet?

    Is column "A" fixed or dynamic?

    Which cells need to relative?
    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
    06-15-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Macro Insert Vlookup Formula

    Well I think I have it figured out. I need I2:J25 to be constant, E8 will actually depend on the row as the formula is copied down (E8, E9, E10, etc). and the Indirect Portion (B8) will be similar to E8.

    The code I am using is:

    With Range("F8:F1000")
    .Formula = "=VLOOKUP(E8,INDIRECT(""'""&B8&""'!I2:J25""),2,FALSE)"
    End With

+ 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