+ Reply to Thread
Results 1 to 3 of 3

Excel Formula for Counting Consecutive Zeros

  1. #1
    Registered User
    Join Date
    12-26-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    2

    Angry Excel Formula for Counting Consecutive Zeros

    Good Afternoon:

    I created an excel formula to count the number of consecutive zeros in a column. I am interested in one consecutive zero, two consecutive zeros, three consecutive zeros, etc...

    I used the following formula:

    =SUM(IF(FREQUENCY(IF(P$2:P$279=0,ROW(P$2:P$279)),IF(P$2:P$279<>0,ROW(P$2:P$279)))=W2,FREQUENCY(IF(P$2:P$279=0,ROW(P$2:P$279)),IF(P$2:P$279<>0,ROW(P$2:P$279)))))

    The formula works 98% of the time. It generally produces the correct number of consecutive zeros, however, occassionally it will indicate there are 15 sets of zeros = 15. Can anyone provide any guidance as to what should be done with this formula?

    Thank you for your time.

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

    Re: Excel Formula for Counting Consecutive Zeros

    what's in W2? I assume that's the number of consecutive zeroes that you wish to count? If that's 5 for instance then that formula will give the number of sets of exactly 5 zeroes multiplied by 5, e.g. if there are 3 sets of 5 zeroes it will return 15. If you just want the result to be 3 use

    =SUM(IF(FREQUENCY(IF(P$2:P$279=0,ROW(P$2:P$279)),IF(P$2:P$279<>0,ROW(P$2:P$279)))=W2,1))

    confirmed with CTRL+SHIFT+ENTER

    Note that truly blank cells in P2:P279 will also be counted as zeroes (although the formula could be altered to stop that).....

  3. #3
    Registered User
    Join Date
    12-26-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    2

    Thumbs up Re: Excel Formula for Counting Consecutive Zeros

    Thanks, Daddylonglegs. Yes, W2 was the number of consecutive zeros. That worked perfectly! Thanks again!

+ 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