+ Reply to Thread
Results 1 to 10 of 10

non contiguous range in SUMPRODUCT

  1. #1
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    non contiguous range in SUMPRODUCT

    I'm having trouble using a non contiguous range in SUMPRODUCT. I'm testing for the presence of "x" in a range of cells: C13,G13,K13,O13,S13,W13
    with this formula
    SUMPRODUCT(0+(C13,G13,K13,O13,S13,W13="x"))
    #VALUE! error.

    However, if I just work one cell like SUMPRODUCT(0+(C13="x")), I get the correct response.

    how can I get around this?

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: non contiguous range in SUMPRODUCT

    Hi

    One way is this

    =SUMPRODUCT(0+(C13="x")+(G13="x")+(K13="x")+..(others cells)..........)
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Valued Forum Contributor
    Join Date
    03-25-2004
    Location
    Boston, MA US
    Posts
    1,094

    Re: non contiguous range in SUMPRODUCT

    Hi,

    You could try:

    =SUM(COUNTIF(INDIRECT({"C13","G13","O13","S13","W13"}),"a")).

    This would obviously become unwieldy if your range expands greatly. There VBA functions you could create also.

    HTH
    Steve

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

    Re: non contiguous range in SUMPRODUCT

    or:

    =SUMPRODUCT((MOD(COLUMN(C13:W13)-COLUMN(C13),4)=0)*(C13:W13="x"))
    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.

  5. #5
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: non contiguous range in SUMPRODUCT

    I tested all three solutions and they all work. bravo!

    However, i cannot figure out how "SUMPRODUCT((MOD(COLUMN(C13:W13)-COLUMN(C13),4)=0)*(C13:W13="x"))" doesn't look in any cells other than the ones in my original list. But I thoroughly tested it and it does. When I click in the formula all the cell are highlighted.

    Thanks All
    Robert

  6. #6
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: non contiguous range in SUMPRODUCT

    or,

    Enter column numbers in a range eg: A2:A10

    In A2 for C13, enter 3 (C is third column), A3 = 7 for G13 (G is 7th column), A4 = 11 for K13 (K is 11th column) etc...

    Then,

    =SUMPRODUCT(ISNUMBER(MATCH(COLUMN(C13:Z13),A2:A10,0))*(C13:Z13="x"))

    You can add/delete column numbers in A2:A10 if you want to include/exclude to count.
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

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

    Re: non contiguous range in SUMPRODUCT

    Quote Originally Posted by Hammer_757 View Post
    I tested all three solutions and they all work. bravo!

    However, i cannot figure out how "SUMPRODUCT((MOD(COLUMN(C13:W13)-COLUMN(C13),4)=0)*(C13:W13="x"))" doesn't look in any cells other than the ones in my original list. But I thoroughly tested it and it does. When I click in the formula all the cell are highlighted.

    Thanks All
    Robert
    This part (MOD(COLUMN(C13:W13)-COLUMN(C13),4)=0) checks the column number to ensure that it is divisable by 4 with no remainder... that tells the formula to enter a TRUE for every 4th column.. then it multiplies that array of TRUEs and FALSEs by the corresponding array of TRUEs and FALSEs indicating where there are "x"'s. So only the columns with "x's" will be counted at every 4th column after column C... so "x's" in other columns won't be counted...

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

    Re: non contiguous range in SUMPRODUCT

    Quote Originally Posted by Fotis1991 View Post
    =SUMPRODUCT(0+(C13="x")+(G13="x")+(K13="x")+..(others cells)..........)
    Note that SUMPRODUCT is redundant in this version - you can use simply

    =(C13="x")+(G13="x")+(K13="x")+(O13="x")+(S13="x")+(W13="x")
    Audere est facere

  9. #9
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: non contiguous range in SUMPRODUCT

    Absolute logical!

    I'll keep in my mind!

    Thanks again.

  10. #10
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: non contiguous range in SUMPRODUCT

    That's impressive! thanks for taking the time to explain it to me.
    Robert

    Quote Originally Posted by NBVC View Post
    This part (MOD(COLUMN(C13:W13)-COLUMN(C13),4)=0) checks the column number to ensure that it is divisable by 4 with no remainder... that tells the formula to enter a TRUE for every 4th column.. then it multiplies that array of TRUEs and FALSEs by the corresponding array of TRUEs and FALSEs indicating where there are "x"'s. So only the columns with "x's" will be counted at every 4th column after column C... so "x's" in other columns won't be counted...

+ 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