+ Reply to Thread
Results 1 to 7 of 7

Find location and number of consecutive occurrences of 1 repeated ≥25 times in a column

  1. #1
    Registered User
    Join Date
    08-30-2020
    Location
    New York
    MS-Off Ver
    2020
    Posts
    6

    Find location and number of consecutive occurrences of 1 repeated ≥25 times in a column

    Hi,

    I have Column A with numbers 1,2,3,etc to signify the location of cells in Column B. In Column B, I only have 0s and 1s. I want to identify where in Column B "1" consecutively appears 25 or more times, and how many times it appears. So if 1 appears 27 times beginning where Column A says 5, I would like Excel to paste the number 5 (and subsequent numbers where 1 appears≥25x) to Column D, and also 26 in Column E.
    I have attached an example workbook showing this.

    I did some research and found some answered questions that might help:

    "Counting the number of consecutive occurrences" by timmycl_7 on Excel forum could be useful
    I think the above link would really help with my problem, but I can't figure out how to apply it to my data (Excel newbie here). The forum won't let me attach my link because I am a new user.

    This might also be helpful:
    "Counting streaks in Excel" by Danielpeam

    I would be grateful for any ideas and answers!
    Attached Files Attached Files

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find location and number of consecutive occurrences of 1 repeated ≥25 times in a colum

    Hi,

    So the column A entries are always consecutive integers beginning at 1?

    If so, and you put your threshold for consecutive 1s (e.g. 25) in C1, then:

    In D2:

    =IFERROR(AGGREGATE(15,6,A$2:A$41/(MID(CONCAT(0,B$2:B$41),A$2:A$41,C$1+1)=0&REPT(1,C$1)),ROWS(A$2:A2)),"")

    In E2:

    =IF(D2="","",IFERROR(MATCH(0,B$41:INDEX(B$2:B$41,D2),0)-1,C$1))

    Copy both down until you start to get blanks for the results.

    Note that if your actual data comprises more than 32,767 rows then this set-up will error. If that's the case I can give you an alternative solution.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    08-30-2020
    Location
    New York
    MS-Off Ver
    2020
    Posts
    6

    Re: Find location and number of consecutive occurrences of 1 repeated ≥25 times in a colum

    Hi XOR LX, thank you so much! This mostly worked, but there is just one problem with the second formula (in E2). I forgot to mention in that in Column B, there are also dashes (-). I only want rows containing 1s. However, if I have 25 1s followed by 4 dashes, the formula will give me 29. How can I fix this?

    (I've attached a new spreadsheet with the a very long column of data containing 0s, dashes, and 1s in column B to show what I mean).
    Attached Files Attached Files
    Last edited by montana7244; 09-05-2020 at 04:21 PM.

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find location and number of consecutive occurrences of 1 repeated ≥25 times in a colum

    Hi,

    Does this adjustment fix it for you?

    In E3:

    =IF(D3="","",IFERROR(MIN(MATCH({0,"-"},B$7500:INDEX(B$2:B$7500,D3),0))-1,C$1))

    By the way, I noticed that you'd committed the column D formulas as array formulas, i.e. with CTRL+SHIFT+ENTER - they don't need to be, in fact.

    Regards

  5. #5
    Registered User
    Join Date
    08-30-2020
    Location
    New York
    MS-Off Ver
    2020
    Posts
    6

    Re: Find location and number of consecutive occurrences of 1 repeated ≥25 times in a colum

    Hi,

    The adjustment worked for everything but the last 3 cells (D11:D13). These last 3 cells say "25" for number of occurrences, when they are actually 117, 78, and 111 respectively.
    This is happening because the formula is encountering some error, causing it to give the content (25) of cell C1 as the output. But I am not sure what the error is.
    I've attached the spreadsheet to show you what is happening.
    How do you fix this?

    Thank you!
    Montana
    Attached Files Attached Files

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find location and number of consecutive occurrences of 1 repeated ≥25 times in a colum

    Ah yes, of course. Apologies. Use:

    =IF(D3="","",IFERROR(AGGREGATE(15,6,MATCH({0,"-"},B$7500:INDEX(B$2:B$7500,D3),0),1)-1,C$1))

    instead.

    Regards

  7. #7
    Registered User
    Join Date
    08-30-2020
    Location
    New York
    MS-Off Ver
    2020
    Posts
    6

    Re: Find location and number of consecutive occurrences of 1 repeated ≥25 times in a colum

    Thank you so much, it works! You've really made my day. This is incredibly helpful for me! The formulas will save me so much time.
    I hope you have a great week.
    Montana
    Last edited by montana7244; 09-08-2020 at 03:26 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Repeated words: remove duplicates, display word along with the number of times repeated
    By number9 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-24-2019, 03:32 PM
  2. Count the number of occurrences of consecutive absences
    By MissC in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-28-2017, 11:18 PM
  3. Count Repeated Occurrences in a Column
    By gra0001 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-05-2016, 08:00 AM
  4. Replies: 2
    Last Post: 11-30-2012, 12:48 PM
  5. Count the number of consecutive occurrences
    By timmycl_7 in forum Excel General
    Replies: 12
    Last Post: 05-03-2012, 02:04 PM
  6. Find 4 consecutive occurrences
    By swatsp0p in forum Excel General
    Replies: 8
    Last Post: 03-27-2010, 01:55 PM
  7. find out number repeated max. times in column.
    By vimivijay in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2005, 06:59 AM

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