+ Reply to Thread
Results 1 to 7 of 7

Absolute ref from relative in VBA

  1. #1
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Absolute ref from relative in VBA

    I want VBA to insert a formula into the current cell which has an absolute reference to one cell and a relative to another. I tried recording something & got the following:

    Please Login or Register  to view this content.
    This does get me absolute & relative references, but the absolute is hard-wired into the macro. I want to create an absolute reference from a relative one. I tried the following:

    Please Login or Register  to view this content.
    This resulted in an error. I want to use the macro regardless of what the active cell is, and always end up with a relative reference to the cell to the immediate left, and an absolute ref to the cell immediately above the active cell.

    Any help appreciated.
    Last edited by gjcase; 09-29-2011 at 09:05 PM. Reason: marr solved

  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: Absolute ref from relative in VBA

    Hello gjcase,

    Rather than trying to explain the problem using formulas, try using cell addresses. Provide before and after examples of with details of what should happen with the addresses and what they should look like.
    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
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: Absolute ref from relative in VBA

    Okay, Leith, thanks for the response.

    I am trying to write a macro which will create a formula in the current cell as follows:

    If the current active cell is B5, on executing the macro, I want the result in B5 to be

    =A5 + $B$4

    If the current active cell is H14, on executing the macro, I want H1 to contain the formula

    =G14 + $H$13

    I'm sure there's an easy way to do this, it just eludes me. Any help appreciated.

  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: Absolute ref from relative in VBA

    Hello gjcase,

    Is this statement correct or should it have been H14 instead of H1?
    If the current active cell is H14, on executing the macro, I want H1 to contain the formula

  5. #5
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: Absolute ref from relative in VBA

    Sorry, should have been H14, happy fingers, you know...

  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: Absolute ref from relative in VBA

    Hello gjcase,

    This should do it.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: Absolute ref from relative in VBA

    Exactly what I'm after. Thank-you, sir.

+ 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