+ Reply to Thread
Results 1 to 6 of 6

Count X amount of numbers between #1 occurs

  1. #1
    Registered User
    Join Date
    04-27-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Question Count X amount of numbers between #1 occurs

    Best way to explain this question is by example
    I have a column of numbers

    Column X
    1
    2
    3
    4
    1
    4
    5
    6
    7
    8
    2

    1

    The biggest gap in between the number 1 occurring is 6 times as bold above. How can i using excel formula or VBA highlight this, especially in a much larger range of data (like 15000 Lines)

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

    Re: Count X amount of numbers between #1 occurs

    Try this array formula, assuming your data is in A1:A15000

    =MAX(FREQUENCY(IF(A1:A15000<>1,ROW(A1:A15000)),IF(A1:A15000=1,ROW(A1:A15000))))

    confirmed with CTRL+SHIFT+ENTER
    Audere est facere

  3. #3
    Valued Forum Contributor
    Join Date
    10-17-2010
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013, 2016, 2019, 365
    Posts
    294

    Re: Count X amount of numbers between #1 occurs

    There's probably a more elegant way, but I find helper columns easiest to see what's going on.
    Suppose your list starts at A2.
    In B2, put
    =IF(A2=1,1,b1+1)

    Copy that down, and take the MAX of that column, =MAX(B:B)

    You might need to change the first cell if A2<>1 (might give an error, depending on what's in b1!).

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,601

    Re: Count X amount of numbers between #1 occurs

    For me that resturn all empty cells after last occure...

    Maybe this:

    =MAX(FREQUENCY(IF(A1:A15000<>"";ROW(A1:A15000));IF(A1:A15000=1;ROW(A1:A15000))))

  5. #5
    Valued Forum Contributor
    Join Date
    10-17-2010
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013, 2016, 2019, 365
    Posts
    294

    Re: Count X amount of numbers between #1 occurs

    See? daddylonglegs is much more elegant!

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,601

    Re: Count X amount of numbers between #1 occurs

    Your approach is not bad either.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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