+ Reply to Thread
Results 1 to 8 of 8

how to sum up based on a cell's value

  1. #1
    Registered User
    Join Date
    11-02-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    81

    how to sum up based on a cell's value

    Hi, I want to do sum-up for the 2nd row with cells: A2, B2, C2, D2, E2, F2, G2, H2, based on the value of cell J2:

    If J1="Odd", then sum up A2, C2, E2 and G2
    If J1="Even", then sum up B2, D2, F2, and H2.

    How can I make this with a formula?


    If I want to do sum-up for column B with cells: B11, B12, B13, B14, B15, B16, B17, B18:

    If J1="Odd", then sum up B11, B13, B15, B17
    If J1="Even", then sum up B12, B14, B16, B18

    How can I do this?

    The example is attached here. Thanks for your help.
    Attached Files Attached Files

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: how to sum up based on a cell's value

    You can do this:

    =IF(MOD(J1,2)=1,SUM(A2,C2,E2,G2),SUM(B2,D2,F2,H2))

    and for your second query:

    =IF(MOD(J1,2)=1,SUM(B11,B13,B15,B17),SUM(B12,B14,B16,B18))

    Hope this helps.

    Pete

  3. #3
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: how to sum up based on a cell's value

    Hi zjianguk

    In K1:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Array formula: CTRL + SHIFT + ENTER
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: how to sum up based on a cell's value

    One way...

    Assuming J2 will always contain either Even or Odd.

    =SUMPRODUCT(--(MOD(COLUMN(A2:H2),2)=--(J2="odd")),A2:H2)
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: how to sum up based on a cell's value

    And another way:
    =SUMPRODUCT(VLOOKUP(A2,A2:H2,IF(J2="ODD",{1,3,5,7},{2,4,6,8})))
    Quang PT

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: how to sum up based on a cell's value

    It seems that J1 contains the words "Odd" or "Even" rather than containing a number, so you can do this:

    =IF(J1="Odd",SUM(A2,C2,E2,G2),SUM(B2,D2,F2,H2))

    or:

    =IF(J1="Odd",SUM(B11,B13,B15,B17),SUM(B12,B14,B16,B18))

    Hope this helps.

    Pete

  7. #7
    Registered User
    Join Date
    11-02-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: how to sum up based on a cell's value

    Hi everyone, Pete, bebo, Tony, Kevin, thanks for all your nice solutions. I've written them down for myself.

    I'm sure this will be useful to others as well

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: how to sum up based on a cell's value

    You're welcome. We appreciate the feedback!

+ 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