+ Reply to Thread
Results 1 to 13 of 13

Sum corresponding cells on various sheets if a condition is met

  1. #1
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Question Sum corresponding cells on various sheets if a condition is met

    Hi,

    I'm quite new here and a self taught beginner so forgive me if my phrasing is poor and question rather simple.

    I'll explain as best I can:

    I have a work book with 10 sheet all with the same input set up to record figures. As it stands I have a summary sheet at the end that totals values from the 10 sheets using the following code:

    =IF(SUM(Sheet1:Sheet10!C3)>0, SUM(Sheet1:Sheet10!C3),"")
    =IF(SUM(Sheet1:Sheet10!C4)>0, SUM(Sheet1:Sheet10!C4),"")
    =IF(SUM(Sheet1:Sheet10!C5)>0, SUM(Sheet1:Sheet10!C5),"")

    and so on up to C30

    I want to divide this information into 2 different sub totals, using the data validation option I have a list selection cell on each sheet with 2 options, lets call them "option a" and "option b" This list cell is located in J43 on all sheets.

    As each sheet will be designated 1 or the another, I was hoping to be able to total up the values of just the option a's and then just the option b's. The part where it checks that the value is greater than zero isn't compulsory

    I'll express my desire in terms of my dodgy attempt at what I think the code could potentially look like:

    =SUMIF(Sheet1:Sheet10, J43="option a", Sheet1:Sheet10!C3)

    So to reiterate, I want to add the values in cell C3 on the sheets sheets where cell J43 equals option a.

    From there I can extrapolate the code myself to work in the neighboring cells and reverse the option to obtain all of the option b's.

    Thank you for your time,

    Mick.
    Last edited by mick86; 08-10-2010 at 03:44 AM. Reason: slight typo plus added solved prefix

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: How to sum corresponding cells on various sheets if a condition is met

    Try:

    Please Login or Register  to view this content.
    copied down
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: How to sum corresponding cells on various sheets if a condition is met

    WOW, that works exactly how I needed it to. I copied it down and tested it and its perfect. I was also able to manipulate it to show all the option b's and cell data from the same rows but different columns. I don't completely understand how it all works but I am able to use it to extract all the data I need.

    To hide all of the cells returning zero I just formatted the cell as custom and used the following option:
    0;-0;;@ The only down side was that I can no longer have therm formatted in the currency format like this (they display similar to a general number), but that's okay.

    My coding attempt was way off, but at least you could understand my intentions. Thank you very much for that, I'll have to do some research into the SUMPRODUCT and INDIRECT commands so that I can better understand just how that code works.

    Thanks again.

    Note: Just noticed that if I rename the sheets the code doesn't automatically update.. Is there a simple way to allow the sheet references to update if the sheets names are changed? My original code just to total up references from all sheets would change the sheet names in the code automatically if the sheets were renamed.
    Last edited by mick86; 08-10-2010 at 05:11 AM. Reason: Additional note

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: How to sum corresponding cells on various sheets if a condition is met

    This part: "'Sheet"&ROW(INDIRECT("1:10") says you have sheets named Sheet1 to Sheet10

    Renaming sheets will throw off the formula.

    If you rename them with a similar consistent naming scheme, for example Table1, Table2, Table3, etc... then you can adapt the formula easily enought... but if you rename the sheets uniquely like: ThisSheet, ThatSheet, Summary then you will need to create a list of those sheetnames somewhere and then select that range and name it through Insert|Name|Define (call it TabNames) and revise the formula to something like:

    =SUMPRODUCT(SUMIF(INDIRECT("'"&TabNames&"'!J43"),"a option",INDIRECT("'"&TabNames&"'!C"&ROWS($A$1:$A$3))))

  5. #5
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: How to sum corresponding cells on various sheets if a condition is met

    The names used on sheets are peoples names. I tried typing the names on a separate sheet in a vertical list, selecting those cells and naming that range TabNames (using the input boxt in the upper left of the tool bar) and by right clicking and selecting name range, but it returned error codes.

    I have settled for the moment to keeping the sheet names standard and placing an index file at the beginning to list the corresponding peoples names and match them with the sheets.

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: How to sum corresponding cells on various sheets if a condition is met

    I just double-checked the formula and it does work... but you can choose the method you want to use.

  7. #7
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: How to sum corresponding cells on various sheets if a condition is met

    Ahh, you're absolutely correct. Where I went wrong was that I had left some blanks at the end of my named range, every cell needs to have a name that matches with a sheet. Thank you, your very skilled.

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: How to sum corresponding cells on various sheets if a condition is met

    There are ways to make a dynamic named range so that you can have blanks in the range and you can add more items as required without having to adjust the range itself in the Named range definition.

    See here: http://www.contextures.com/xlnames01.html#Dynamic

  9. #9
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Sum corresponding cells on various sheets if a condition is met

    I'll have to look into that. Thanks.

  10. #10
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Sum corresponding cells on various sheets if a condition is met

    Hello,

    Sorry to other you yet again, I was hoping you might be willing to add to the code you came up with for me last time. Would it be difficult to add a second condition to the code, same format as the first just a second reference point and condition check.

    The successful code as it stands that uses one condition to return a value:

    =SUMPRODUCT(SUMIF(INDIRECT("'Sheet"&ROW(INDIRECT("1:21"))&"'!M43"),"Condition1",INDIRECT("'Sheet"&ROW(INDIRECT("1:21"))&"'!R"&ROWS($A$1:$A35))))

    I wish to additionally test the value of Q43 on each sheet before returning the figure (checking against a text value for yes/no as above).

    To reiterate, same scenario as above with 2 cell value checks both needing to be true before summing numbers.

    If you or other could offer some assistance I'd very much appreciate your help,

    Mick.

  11. #11
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Sum corresponding cells on various sheets if a condition is met

    bump

    in the hopes of a response

  12. #12
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum corresponding cells on various sheets if a condition is met

    Try:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Smile Re: Sum corresponding cells on various sheets if a condition is met

    I again offer you a very sincere thank you, your code works perfect, that's exactly what I was looking for.

    Had I continued to try to solve this problem alone, I would have probably spent at least a week researching and trying through trial and error and even then I'm not confident that I could have solved it.

    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