+ Reply to Thread
Results 1 to 5 of 5

Use VBA to create and insert an indirect relative formula

  1. #1
    Registered User
    Join Date
    05-08-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    2

    Use VBA to create and insert an indirect relative formula

    I imagine it is, but I can't seem to get it quite to work. I'm two days into youtube videos and forum hunting and could use some help!

    I think I'm close with object variables as a range but I can't seem to get the formula to use the formula contained in another cell, much less offset a given amount from that range. I tried it as a string, but then I couldn't use offsets.

    I want to:

    1st) define a variable as a range (a single cell) referenced in formula(not the value) in another cell
    2nd) use that range with offsets to make a FormulaR1C1 formula.

    Please Login or Register  to view this content.
    Say Cell A1{activecell} = A3

    And I want the Formula in B1{always activecell.offset(0,1)} to = Sum(B3{always the same row number as the formula in A1, and offset 1 column to the right},B13{always activecell.offset(10,1)},B23{always activecell.offset(20.1)})

    Please help!
    Last edited by Leith Ross; 05-08-2015 at 06:07 PM. Reason: Added Code Tags

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Hello VBA Masters, is this possible?

    cdratz,
    It seems it is the first time you are with us, but there is some rules:
    Code tags when posting code
    Explicit Title
    Can you update your thread
    - Battle without fear gives no glory - Just try

  3. #3
    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: Hello VBA Masters, is this possible?

    Hello cdratz,

    Welcome to the Forum!

    I changed the title for you.

    This VBA macro will place the relative R1C1 formula in the cell directly to the right of the active cell. The formula will sum the cells in the same column as the formula 2 rows down, 12 rows, and 22 rows down. Using cell A1 as the active cell the summed cells are B3, B13, and B23.

    Please Login or Register  to view this content.
    EDIT:
    After looking at this again, I think this the macro you want to use. The first macro does not use the row number of the cell in A1. This one does.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 05-08-2015 at 07:38 PM.
    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!)

  4. #4
    Registered User
    Join Date
    05-08-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    2

    Re: Use VBA to create and insert an indirect relative formula

    Thanks for the response Leith, and for the title change.

    On the second version you posted, I ran into method 'range' of 'object '_global' failed error.

    I see how your suggested macros are working, which will have some unrelated beneficial impact, but for this one in particular I am interested not in the absolute cell address of the active cell, I'm interested in the cell reference contained in the active cell.

    In my example I said A1 was the active cell and it had the formula "=A3", it is that A3 that I would like to base all of the relative references in my sum formula on.

    Maybe instead of defining the variables based on the active cell is there a way to define them based on the cell referenced in the active cell?

    -Chris

  5. #5
    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: Use VBA to create and insert an indirect relative formula

    Hello cdratz,

    The second macros works for me. Since you are using Excel 2010 and I am too, there should be no compatibility issues.

    Do you have code elsewhere in the workbook?

    EDIT:
    I was able to reproduce the error by changing the A1 to "=A3". This is not a valid range reference in Excel or VBA. This will return the value of A3. Put "A3" in cell A1 and it will work.
    Last edited by Leith Ross; 05-08-2015 at 08:39 PM.

+ 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. [SOLVED] Making the last part of this INDIRECT formula as relative
    By zicitron in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-04-2020, 02:26 PM
  2. How to insert a relative dynamic formula in VBA
    By arskiracer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2013, 12:29 AM
  3. Create macro to insert rows relative to the value
    By ofranco in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-03-2012, 04:19 PM
  4. Replies: 5
    Last Post: 02-18-2011, 05:27 AM
  5. Relative Indirect Formula Referencing?
    By Damian in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-07-2005, 02:19 AM

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