+ Reply to Thread
Results 1 to 4 of 4

Calculating the largest consecutive gap in a series of numbers

  1. #1
    Registered User
    Join Date
    03-29-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    1

    Calculating the largest consecutive gap in a series of numbers

    Hiya,

    I am currently trying to calculate the largest gap in a series of numbers where a particular number has not appeared and display this number in a cell.

    For example,

    There are 2 numbers involved, 0 and 1. My spreadsheet looks like:

    A1
    A2 1
    A3 0
    A4 0
    A5 0
    A6 0
    A7 1
    A8 0
    A9 0 and so on.....

    Now, in cell C1 I want excel to automatically calculate the number of times 0 has come up consecutively up to the last time the number 1 appeared. So when inputting data downwards in A10, A11, A12 it will be able to tell me how many consecutive 0's there have been until the last number 1 appeared.

    In the above example, if I had input the data upto A5, C1 would display the number 3 (there have been three 0's since the last 1 came up). When A6 is filled in with a 0, C1 would display 4, yet once A7 had been filled in the counter would reset back to 0 in C1.

    I have tried to explain this as best as I can, if you need any clarification please ask, and thank you kindly in advance,

    Dave

  2. #2
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Calculating the largest consecutive gap in a series of numbers

    Try the following formula, which needs to be confirmed with CONTROL+SHIFT+ENTER, not just ENTER...

    =COUNTIF(INDEX(A2:A65536,MATCH(2,1/(A2:A65536=1))):INDEX(A2:A65536,MATCH(9.99999999999999E+307,A2:A65536)),0)

    Note that if the number 1 does not occur at least once in the data, the formula will return #N/A. If this is the case, the formula would need to be modified.

    Hope this helps!

    xl-central.com

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Calculating the largest consecutive gap in a series of numbers

    You posted this exact question in another forum WITHOUT letting either
    group know about the other! That means if you receive an solution from one
    group, the other group will be wasting their time on your solved problem,
    when they could be helping others.

    At least, post a link to the other forum so our members can keep
    track of the progress there.

  4. #4
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Calculating the largest consecutive gap in a series of numbers

    This seems to work:

    copy this into column B from B2 downwards

    =IF(A2=1,0,IF(AND(A2=0,A1=0),B1+1,1))

    Then in C2 use Ctrl-Shift-Enter to insert the formula

    =INDEX(B2:B50,MAX((ABS(B2:B50)>0)*ROW(B2:B50))-(CELL("Row",B2)-1))
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

+ 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