+ Reply to Thread
Results 1 to 6 of 6

Conditional addition

  1. #1
    Registered User
    Join Date
    11-03-2009
    Location
    montreal
    MS-Off Ver
    Excel 2004
    Posts
    3

    Conditional addition

    In my spread sheet I have multiple columns - labeled -

    hours / module / hours / module / hours / module
    4 / 1 / 2 / 2 / 6 / 3
    4 / 1 / 4 / 2 / 4 / 4
    4 / 2 / 4 / 2 / 4 / 4

    each row = a week in a year

    module 1 = total hours worked ?????
    module 2 = total hours worked ?????

    The modules are schools modules, which need to be completed by each student. The hours column on the left of the module column indicates the hours worked in that module. (the above example - 4 hours worked in Module 1 / 2 hours worked in module 2 / 6 hours worked in module 3).

    What is the most effective way to create an automatic calculator that adds up all of the hours worked in each of the Modules

    How many hours worked in module 1
    How many hours worked in module 2 etc??
    Last edited by matralab; 11-03-2009 at 02:53 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    re: Conditional addition

    EDIT: below was based on your initial sample of data (ie week1, week2, week3 in first column)

    the layout of your data is not I'm afraid particularly conducive to easy analysis

    If we assume your present layout is in range A1:G4 with headers in B1:G1 and weeks in A2:A4 then to sum say module 1

    Module1:
    =SUMPRODUCT((MOD(COLUMN($C$2:$G$4),2)=1)*($C$2:$G$4=1)*$B$2:$F$4)

    the text in red can be a cell reference containing the module number of interest.

  3. #3
    Registered User
    Join Date
    11-03-2009
    Location
    montreal
    MS-Off Ver
    Excel 2004
    Posts
    3

    Re: Conditional addition

    Hi

    Thank you for your response, however - I am unclear on your equation...

    =SUMPRODUCT((MOD(COLUMN($C$2:$G$4),2)=1)*($C$2:$G$4=1)*$B$2:$F$4)

    ((MOD(COLUMN($C$2:$G$4),2)=1)
    What is happening here - should I be putting the MOD number - or the Column number. What is $C or $2

    Sumproduct is used to add up arrays - but everything else is a little difficult to explain. I believe you understood the question perfectly - but just in case, I attached the spreadsheet.

    Thanks in advance for any clarification.
    Attached Files Attached Files

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Conditional addition

    Based on your sample file...

    First you should correct O26 - should be 25 rather than 24.

    Then based on your modules (numbers with exception of "A") you can use

    Please Login or Register  to view this content.
    The above (in essence)y checks that the column of each cell in the range referenced is odd (C,E etc) and that the value within the cell being iterated equals Module of interest and multiplies the numerical value from the cell to the left of the cell being iterated by 1 or 0 depending on whether both prior conditions held true (ie module match and column being processed is odd).

    The SUBSTITUTE is used to handle the fact that some cells within the range contain "A" (removed) and the 0& to account for the fact that some will be blank/null

    Both features combined ensure that when the value in the cell to the left is * by 0/1 the value is numeric in nature... if not the SUMPRODUCT would generate a #VALUE! error eg:

    TRUE*TRUE*"a" --> #VALUE!

    whereas

    TRUE*TRUE*"0" -> 0

    (Boolean TRUE/FALSE when coerced become 1/0 respectively)
    Last edited by DonkeyOte; 11-06-2009 at 09:47 AM. Reason: rephrased

  5. #5
    Registered User
    Join Date
    11-03-2009
    Location
    montreal
    MS-Off Ver
    Excel 2004
    Posts
    3

    Re: Conditional addition

    Wow! I still don't understand it fully - but thanks SOOO much!!

    I am reading through your recommended reading files - thanks again!

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Conditional addition

    No problem. FWIW I have since your last post rephrased my prior reply for sake of clarity (I hope?)

    On an aside please also remember to mark thread as solved if you're happy you have a workable solution.

+ 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