+ Reply to Thread
Results 1 to 9 of 9

Copying SUMIF to reference sequential columns

  1. #1
    Registered User
    Join Date
    03-18-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2007
    Posts
    3

    Copying SUMIF to reference sequential columns

    First time poster...first time I've run into an Excel issue I haven't been able to solve!

    I am using an SUMIF formula to look for any instances of specific criteria (in this case “test”) in a range of cells and to total the amount(s) found in another range. I’m starting with:

    B19=SUMIF($A$3:$A$13, "*test*",$B$3:$B$13)

    However, as I increase in rows, I want Excel to do SUMIF using the same range to look for criteria but referenencing a different range for the amounts. The range changes to the next adjecnt column. So, when I move to Row 20, I want Excel to look at Column C.

    B20= SUMIF($A$3:$A$13, "*test*",$C$3:$C$13)

    This pattern continues as the rows increase. Thus:

    B21= SUMIF($A$3:$A$13, "*test*",$D$3:$D$13)
    B22= SUMIF($A$3:$A$13, "*test*",$E$3:$E$13)

    And so on.

    Is there a way to force Excel to copy or fill this formula down so that it recognizes to look at the next column as the rows progress?

    I’ve tried filling using series and I’ve attempted to use the ‘offset’ but have not found anything that works. I’m working with rows 19 through 309 so I’d rather not have to retype the formula and update the column reference each time.

    I'm willing to try anything (even macros!) if necssary.

    Any suggestions?

  2. #2
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Copying SUMIF to reference sequential columns

    Try INDIRECT with ADDRESS nested inside.

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Copying SUMIF to reference sequential columns

    Try using INDEX like this in B19 copied down

    =SUMIF($A$3:$A$13,"*test*",INDEX($B$3:$IV$13,0,ROWS(B$19:B19)))

    The part ROWS(B$19:B19) returns 1 in that formula but when you copy down it will increment by 1 each time......and that function is in the "columns" argument for INDEX so you get the sum of column 1 [B3:B13] in B19 then column 2 [C3:C13] in B20 etc.
    Audere est facere

  4. #4
    Registered User
    Join Date
    03-18-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Copying SUMIF to reference sequential columns

    I used this in B19 through B309 and it worked perfectly...until row 274. There through 309 i got a #REF! error. Excel Error Trace "encountered exisiting arrows or a circular reference."

    All other caluclations to that point are correct.

    I sort of understand the INDEX formula but not enough to fix the error myself.

    Thanks for speedy responses!




    Quote Originally Posted by daddylonglegs View Post
    Try using INDEX like this in B19 copied down

    =SUMIF($A$3:$A$13,"*test*",INDEX($B$3:$IV$13,0,ROWS(B$19:B19)))

    The part ROWS(B$19:B19) returns 1 in that formula but when you copy down it will increment by 1 each time......and that function is in the "columns" argument for INDEX so you get the sum of column 1 [B3:B13] in B19 then column 2 [C3:C13] in B20 etc.

  5. #5
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Copying SUMIF to reference sequential columns

    I used:

    SUMIF($A$3:$A$13,"test",INDIRECT(ADDRESS(3,ROW()-16+1)):INDIRECT(ADDRESS(13,ROW()-18+1)))

    and it copies down past there.

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Copying SUMIF to reference sequential columns

    In general it's best to avoid INDIRECT where you can as it's a "volatile" function. Also using INDIRECT and ADDRESS slightly offends my formulaic sensibilities (sorry Bob )......ADDRESS gives you a text address and then INDIRECT converts it to a cell reference.....there's almost always a better way than going round the houses like that, i.e. INDEX in this case.

    The way I wrote the formula, specifically, restricted it.......

    The formula I suggested is limited by the range $B$3:$IV$13. I used IV as the last column because that's the last column in Excel 2003 (force of habit)....as you have Excel 2007 you can extend the range to column XFD or as far as you have data, e.g.

    =SUMIF($A$3:$A$13,"*test*",INDEX($B$3:$XFD$13,0,ROWS(B$19:B19)))

  7. #7
    Registered User
    Join Date
    03-18-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Copying SUMIF to reference sequential columns

    The INDIRECT and ADDRESS formulas did not work for me. While I did not receive errors, I found the totals were not correct after doing some spot-checking.

    I wondered if the INDEX you provided had a column range limit on it. That you do makes perfect sense and is easy to fix...almost wish I would have tried that and solved my own problem.

    Since I'm using B through KF, I updated the formula to extend that far and presto...SUCCESS!

    Thanks so much! You've saved me hours of work, I'm sure.




    Quote Originally Posted by daddylonglegs View Post
    In general it's best to avoid INDIRECT where you can as it's a "volatile" function. Also using INDIRECT and ADDRESS slightly offends my formulaic sensibilities (sorry Bob )......ADDRESS gives you a text address and then INDIRECT converts it to a cell reference.....there's almost always a better way than going round the houses like that, i.e. INDEX in this case.

    The way I wrote the formula, specifically, restricted it.......

    The formula I suggested is limited by the range $B$3:$IV$13. I used IV as the last column because that's the last column in Excel 2003 (force of habit)....as you have Excel 2007 you can extend the range to column XFD or as far as you have data, e.g.

    =SUMIF($A$3:$A$13,"*test*",INDEX($B$3:$XFD$13,0,ROWS(B$19:B19)))

  8. #8
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Copying SUMIF to reference sequential columns

    Sorry, Daddy, didn't mean to offend you . Yours is certainly the more elegant and direct solution,

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Copying SUMIF to reference sequential columns

    Nah....only kidding

    For what it's worth I think the INDIRECT version works OK but you missed the wildcards...in fact as you only need the first cell of the range to make SUMIF work then this would also give the correct results

    =SUMIF($A$3:$A$13,"*test*",INDIRECT(ADDRESS(3,ROW()-17)))

    or with OFFSET

    =SUMIF($A$3:$A$13,"*test*",OFFSET(B$3,,ROW()-19))

    but, again, OFFSET is also volatile (as is SUMIF with only the first cell specified).....and ROWS give you added robustness over ROW when rows are added or deleted from the data.....

+ 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