+ Reply to Thread
Results 1 to 9 of 9

Creating a sumifs formula using relative reference and then copying as absolute to columns

  1. #1
    Registered User
    Join Date
    10-24-2012
    Location
    Guelph, ON
    MS-Off Ver
    Excel 2010
    Posts
    41

    Creating a sumifs formula using relative reference and then copying as absolute to columns

    Hello: I'm stumped. I have a macro that moves the cell into row 2 of a column and this column will change depending on the original data submitted. So I was trying to set up a formula that builds a sumifs formula based on relative references but then copies this across columns to the right of the active cell which means I need absolute references.

    Example in Cell X2 I want the formula to read: =SUMIFS($U:$U,$V:$V,$V2,$R:$R,X$1)
    When this gets copied to Y2 it should read =SUMIFS($U:$U,$V:$V,$V2,$R:$R,Y$1) etc.

    if I enter:
    ActiveCell.FormulaR1C1 = "=SUMIFS(C[-3],C[-2],rc[-2],C[-6],R1C)" it returns =SUMIFS(U:U,V:V,V2,R:R,X$1) in the spreadsheet

    ActiveCell.FormulaR1C1 = "=SUMIFS(C21,C22,RC22,C18,R1C)" doesn't work either because the data won't always be in columns 21, 22, etc.

    I've tried various things including trying to build formulas using & and $ signs but can't figure this one out.

    Anyone have any idea how to make this work?
    Thanks!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Creating a sumifs formula using relative reference and then copying as absolute to col

    Try just using the formula:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: Creating a sumifs formula using relative reference and then copying as absolute to col

    The square brackets make your references relative. R5C1 is an absolute reference for cell $A$5; R[5]C1 is 5 rows below the current cell in column A; R5C[1] is row 5 and 1 column to the right of the current cell ... and so on. So just use the [ ] brackets for the rows/cols you want to be relative. I think you're implying that you can't mix them, but you can (and have as shown in the first example).
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Creating a sumifs formula using relative reference and then copying as absolute to col

    Or, if you must …

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-24-2012
    Location
    Guelph, ON
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Creating a sumifs formula using relative reference and then copying as absolute to col

    Hi there: Thanks for the quick reply! I have tried both ways and it doesn't work because it doesn't anchor the columns I need. They become relative. So in the first case with ActiveCell.FormulaR1C1 = "=SUMIFS(C[-3],C[-2],rc[-2],C[-6],R1C)" it returns =SUMIFS(U:U,V:V,V2,R:R,X$1) in the spreadsheet and I want the U:U to be $U:$U for copying over to the other columns.
    If I use SUMIFS(C21,C22,RC22,C18,R1C)" it works if I have landed in Column X, but what would happen if there are extra columns in the download that I'm applying this macro to and now I need to start these formulas in Column AA for example. Then that formula will be a bit different starting with C25 or whatever. This is a moving target so I need the relative references to create the formula but absolute for copying?

    I tried SUMIFS(C-3,C-2,rc-2,C-6,R1C) but that returns an error - I don't think it likes the negatives. I'm probably not explaining this well. Sorry.

    Right now I'm working on a long formula using INDIRECT and MATCH (I'm looking up the column headers that move depending on the original file) to make this work... I think that way I can get this to work. Will see... I'm getting closer I think! Was hoping for a simple formula but this long one might work.

    Right now I have: =SUMIFS(INDIRECT("$"&SUBSTITUTE(ADDRESS(1,MATCH("actual consumption",1:1,0),4),"1","")&":$"&SUBSTITUTE(ADDRESS(1,MATCH("actual consumption",1:1,0),4),"1","")),INDIRECT("$"&SUBSTITUTE(ADDRESS(1,MATCH("acct",1:1,0),4),"1","")&":$"&SUBSTITUTE(ADDRESS(1,MATCH("acct",1:1,0),4),"1","")),INDIRECT("$"&SUBSTITUTE(ADDRESS(1,MATCH("acct",1:1,0),4),"1","")&"2"),INDIRECT("$"&SUBSTITUTE(ADDRESS(1,MATCH("monthyear",1:1,0),4),"1","")&":$"&SUBSTITUTE(ADDRESS(1,MATCH("monthyear",1:1,0),4),"1","")),X$1)

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Creating a sumifs formula using relative reference and then copying as absolute to col

    Look at post #4 again ... or for a first time, whatever.

    You can just use the actual formula. The only trick is to double up on the quote marks: "" becomes """".

    Or, put your formula into a cell and check that it works. Then start to record a macro. Put the cursor in the cell with the formula and press F2 to go into edit mode. Then press Ctrl-Shift-Enter to re-commit the Array Formula. Then stop the macro recording. Now go find the module where the macro has been recorded ... that will give you the formula you need.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Creating a sumifs formula using relative reference and then copying as absolute to col

    Both of these approaches give absolute column references:

    Please Login or Register  to view this content.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Creating a sumifs formula using relative reference and then copying as absolute to col

    For the big formula, try:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-24-2012
    Location
    Guelph, ON
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Creating a sumifs formula using relative reference and then copying as absolute to col

    Thank you! I did try the #4 and it works. I had gotten the other long formula to work before but this morning I tried your much simpler option and so will use that instead (just easier to read through in the code). I've tested it on other downloads and you are correct, it works! THANK-YOU VERY MUCH! Learned something new and very useful.

+ 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. Replies: 6
    Last Post: 09-30-2016, 03:14 PM
  2. Replies: 5
    Last Post: 09-21-2012, 02:08 PM
  3. Absolute/relative reference
    By eggselent in forum Excel General
    Replies: 2
    Last Post: 05-25-2012, 09:00 AM
  4. Macro formula in relative reference rather than in absolute
    By dlourenco in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-01-2008, 12:05 PM
  5. Replies: 0
    Last Post: 11-15-2007, 02:35 AM
  6. Mixing Absolute and Relative Reference in a Formula
    By tedd13 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-01-2006, 10:10 AM
  7. Replies: 4
    Last Post: 01-07-2006, 09:50 AM

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