+ Reply to Thread
Results 1 to 8 of 8

How To Dynamically Refer To A Cell In A Macro Formula

  1. #1
    Registered User
    Join Date
    09-26-2005
    Posts
    39

    How To Dynamically Refer To A Cell In A Macro Formula

    Greetings:

    I want to write a formula that inserts a column and then does a vlookup in that new column using the cell just to the left of it as the first variable. The problem is, this could be in any random column so I can't do a static reference to $A2 as an example. So, my question is...

    Instead of using =vlookup($A2,Sheet1A1:B50,2,false)

    How do I replace the $A2 part with some code that says, "the cell to the left of here..."
    Last edited by ChrisF79; 02-17-2009 at 11:43 AM.

  2. #2
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: How To Dynamically Refer To A Cell In A Macro Formula

    There are many ways to approach this..

    one is

    activecell.offset( 0 , -1)

  3. #3
    Registered User
    Join Date
    09-26-2005
    Posts
    39

    Re: How To Dynamically Refer To A Cell In A Macro Formula

    Quote Originally Posted by Shijesh Kumar View Post
    There are many ways to approach this..
    activecell.offset( 0 , -1)
    I did try =vlookup(activecell.offset(0,-1),Sheet1......

    It didn't work out though.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: How To Dynamically Refer To A Cell In A Macro Formula

    Please post your code.

  5. #5
    Registered User
    Join Date
    09-26-2005
    Posts
    39

    Re: How To Dynamically Refer To A Cell In A Macro Formula

    ActiveCell.FormulaR1C1 = _
    "=vlookup(Activecell.Offset(0,-1),'[Vlookup Reference.xlsx]Items'!$A:$K,2,false)"

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: How To Dynamically Refer To A Cell In A Macro Formula

    I meant your code in full...

    However if entering a formula in R1C1 format you must obviously use R1C1 notation:

    Please Login or Register  to view this content.
    Also please post your code in CODE tags (use # symbol)

  7. #7
    Registered User
    Join Date
    09-26-2005
    Posts
    39

    Re: How To Dynamically Refer To A Cell In A Macro Formula

    Quote Originally Posted by DonkeyOte View Post
    Please Login or Register  to view this content.
    It works! Thanks so much. Now I understand the R1C1 notation better.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: How To Dynamically Refer To A Cell In A Macro Formula

    Donkey & I have both requested that you use Code Tags, please do so then mark the thread solved
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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