+ Reply to Thread
Results 1 to 4 of 4

Determining longest 'run' of zero values

  1. #1
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 365 v2402
    Posts
    263

    Determining longest 'run' of zero values

    Hi all,

    How would I get Excel to determine the longest 'run' of a given number in a list of numbers? E.g. suppose I have the following data in column A:

    24
    34
    0
    12
    0
    0
    67
    54
    0
    0
    0
    99

    Now suppose I want Excel to look at that data and tell me what the longest consecutive run of zero's are. In this case it would be 3 zero's. But how does I do this?

    Thanks
    -Rob

  2. #2
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474
    I'm not sure if this will do, but try the following...

    1) Enter the text value 'End' at the end of your list of numbers, in this case A13.

    2) Enter the following formula in B1, and copy down:

    =IF(A1=0,MATCH(TRUE,A1:$A$13<>0,0)-1,"")

    ...confirmed with CONTROL+SHIFT+ENTER, not just ENTER.

    3) Enter the following formula in C1:

    =MAX(B1:B12)

    Notice that the range used by the MATCH function includes A13, which contains the text value 'End'. You could always choose to hide this value using 'Conditional Formatting', if you wish.

    Hope this helps!
    Last edited by Domenic; 04-05-2005 at 01:15 PM.

  3. #3
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 365 v2402
    Posts
    263
    Hi Domenic,

    Yes that seems to work, although I'm not entirely sure what it actually does!

    Thanks
    -Rob

  4. #4
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474
    First, the reference to cell A13 should have been absolute. Therefore, the formula should be...

    =IF(A1=0,MATCH(TRUE,A1:$A$13<>0,0)-1,"")

    I've edited my previous post accordingly.

    As for how the formula works...

    For the first two cells, the formula returns an empty string since the corresponding value in Column A does not equal 0, as per the IF function.

    For the third cell, the formula changes to the following...

    =IF(A3=0,MATCH(TRUE,A3:$A$13<>0,0)-1,"")

    Notice that the range for the MATCH function changes. Here's how it breaks down...

    A3:$A$13<>0 returns the following array of values...

    FALSE
    TRUE
    FALSE
    FALSE
    TRUE
    TRUE
    FALSE
    FALSE
    FALSE
    TRUE
    TRUE

    MATCH(TRUE,A3:$A$13<>0,0) returns 2, since TRUE is the second value in the array

    and

    MATCH(TRUE,A3:$A$13<>0,0)-1 returns 1

    For the fourth cell, the formula returns an empty string, since the corresponding value in Column A does not equal 0, as per the IF function.

    For the fifth cell, the formula changes to the following...

    =IF(A5=0,MATCH(TRUE,A5:$A$13<>0,0)-1,"")

    Again, the range for the MATCH function changes. Now...

    A5:$A$13<>0 returns the following array of values...

    FALSE
    FALSE
    TRUE
    TRUE
    FALSE
    FALSE
    FALSE
    TRUE
    TRUE

    Therefore...

    MATCH(TRUE,A5:$A$13<>0,0) returns 3, since TRUE is the third value in the array

    and

    MATCH(TRUE,A5:$A$13<>0,0)-1 returns 2

    This process continues in the same manner until the end. Then the MAX function provides the desired result.

    Hope this helps!

+ 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