+ Reply to Thread
Results 1 to 7 of 7

SUMPRODUCT - Every other column

  1. #1
    Registered User
    Join Date
    03-16-2009
    Location
    SN3 4TN
    MS-Off Ver
    Office 2007/2003
    Posts
    7

    SUMPRODUCT - Every other column

    Hi All,

    I'm after some help with the sumproduct formula.

    I need to count the number of cells <>0.

    My problem is that the cells are not in sequence i.e A1,C1,E1,G1.

    Any idea's ?

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

    Re: SUMPRODUCT - Every other column

    Use:

    =SUMPRODUCT(--(MOD(COLUMN(A1:Z1),2)=1),--(A1:Z1<>0))

  3. #3
    Registered User
    Join Date
    03-16-2009
    Location
    SN3 4TN
    MS-Off Ver
    Office 2007/2003
    Posts
    7

    Re: SUMPRODUCT - Every other column

    Quote Originally Posted by DonkeyOte View Post
    Use:

    =SUMPRODUCT(--(MOD(COLUMN(A1:Z1),2)=1),--(A1:Z1<>0))
    Hi DonkeyOte,

    Can you please explain how this formula works, as I'm getting some strange results.

    Can I assume that the 2 is the column count ?

    Thanks

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

    Re: SUMPRODUCT - Every other column

    The example will Count the instances of "Odd" columns where the value contained within does not equal 0.

    In XL columns can be referred to by their column number ie A=1, B=2 as Z=26 and AA = 27 etc... the example simply tests the Remainder of the Column number once divided by a divisor of 2 --- where the remainder is 1 we know the Column is "odd" (ie A,C,E etc...).

    For more info on MOD See XL Help.

  5. #5
    Registered User
    Join Date
    03-16-2009
    Location
    SN3 4TN
    MS-Off Ver
    Office 2007/2003
    Posts
    7

    Re: SUMPRODUCT - Every other column

    Quote Originally Posted by DonkeyOte View Post
    The example will Count the instances of "Odd" columns where the value contained within does not equal 0.

    In XL columns can be referred to by their column number ie A=1, B=2 as Z=26 and AA = 27 etc... the example simply tests the Remainder of the Column number once divided by a divisor of 2 --- where the remainder is 1 we know the Column is "odd" (ie A,C,E etc...).

    For more info on MOD See XL Help.
    Hi DonkeyOte,

    Thanks, now I understand, but to throw another spanner in the works, what if the columns were not uniform ? i.e A,G,L,M,N,S etc..

    Is there a method where I can select specific cells from specific columns ?

    Thanks in advance for any help/advice

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

    Re: SUMPRODUCT - Every other column

    It will depend on how many you're referring to... you can use a variety of methods in truth but which will be dependent upon the count...

    You could use something as basic as:

    =SUM(--(N(A1)<>0),--(N(G1)<>0),--(N(S1)<>0))+COUNTIF(L1:N1,"<>0")

    ie treat non contiguous ranges slightly differently...

    You could use things like ERROR.TYPE & named range, INDIRECT, CHOOSE but I think we'd need more info.

    Perhaps the easiest option would be to add an indicator in a blank row to denote those to be validated...?
    eg say row 1 had "x" in A, G, L:N, S then you could use the below to count non-zero values in row 2 within those x columns using:

    =SUMPRODUCT(--($A$1:$Z$1="x"),--($A2:$Z2<>0))

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: SUMPRODUCT - Every other column

    You can use another row to indicate the columns of interest:

    =SUMPRODUCT( (A$1:Z$1 = "x") * (A2:Z2<>0) )
    Entia non sunt multiplicanda sine necessitate

+ 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