Identify which row or cell, the start of value 0 be the most appear in sequence.

ibmy

Board Regular
Joined
Mar 4, 2020
Messages
103
Office Version
  1. 2016
Platform
  1. Windows
Hi,

My interest value for the data is "0", zero. The value 0 must be the most appear in sequence. (sorry for my bad english)

Example:

________| Column A
Row 1 : 2
Row 2 : 0 <-
Row 3 : 3
Row 4 : 0 <-
Row 5 : 0 <-
Row 6 : 0 <-
Row 7 : 0 <-
Row 8 : 4
Row 9 : 0 <-
Row 10 : 1
Row 11 : 0 <-
Row 12 : 0 <-
Row 13 : 0 <-
Row 14 : 0 <-
Row 15 : 0 <-
Row 16 : 0 <-
Row 17 : 0 <-
Row 18 : 7
Row 19 : 6
Row 20 : 6
.
.
.

At row 2 and row 9, 0 only appear 1 time and have no sequence.
At row 4 to row 7, 0 appear 4 times.
While at row 11 to 17, 0 appear 7 times.
So row 11 is the start for value 0 to be appear the most in sequence.

Help me on the data 250k row on each column, which row or cell the start for value 0 to be appear the most in sequence.
Thanks.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
See post 3 in this thread

 
Upvote 0
I was able to accomplish this whit few helper cells. first i would start the data in row 2 due to the formula in column C.
Helper Column B simply puts a 1 were ever a 0 appears in column A
Helper Column C is an array formula whey sums the value in B till the next blank cell in B. Hint You have to press Ctrl+Shift+enter to make the the array formula
Cell D1 is the final results.

you can hide both helper Column B & C.

Book1
ABCD
1START OF MOST "0" IN SEQUENCE12
22  
3011
43  
5014
601 
701 
801 
94  
10011
111  
12016
1301 
1401 
1501 
1601 
1701 
187  
196  
206  
216  
Sheet1
 
Upvote 0
I was looking at the formula in the link that I posted and realised that it doesn't work as would be expected, This one works based on your example, but may be a bit slow to calculate with 250k rows. Must be array confirmed with Ctrl Shift Enter.

=SUM(INDEX(FREQUENCY(ROW(A1:A20),IF(A1:A20<>0,ROW(A1:A20))),N(IF({1},ROW(INDEX(A:A,1):INDEX(A:A,MATCH(MAX(FREQUENCY(ROW(A1:A20),IF(A1:A20<>0,ROW(A1:A20)))),FREQUENCY(ROW(A1:A20),IF(A1:A20<>0,ROW(A1:A20))),0)-1))))),1)

I'm going to take a look and see if I can improve it while you test it with smaller data sets to confirm that the results are as expected.
 
Upvote 0
I found that there was an error if the max consecutive zero's starts in row 1, fixing that caused an error if there were no zero's anywhere in the column. This revised formula corrects both problems, although it is far from efficient.

=IF(COUNTIF(A:A,0)=0,"N/A",IFERROR(SUM(INDEX(FREQUENCY(ROW(A1:A20),IF(A1:A20<>0,ROW(A1:A20))),N(IF({1},ROW(INDEX(A:A,1):INDEX(A:A,MATCH(MAX(FREQUENCY(ROW(A1:A20),IF(A1:A20<>0,ROW(A1:A20)))),FREQUENCY(ROW(A1:A20),IF(A1:A20<>0,ROW(A1:A20))),0)-1))))),1),1))

I think that a multiple column approach similar to @hajiali's suggestion would be better than a single formula.
 
Upvote 0
It assumes that your data starts at A1 and that Column B is empty and free to use.
Code:
Sub AAAAA()
Dim lr As Long, highNr As Long, highNrRow As Range
lr = Cells(Rows.Count, 1).End(xlUp).Row
    With Range("A2:A" & lr).Offset(, 1)
        .Formula = "=IF(RC[-1]<>0,"""",IF(AND(RC[-1]=0,R[-1]C[-1]=0),R[-1]C+1, 1))"
        .Value = .Value
    End With
    highNr = Application.Max(Columns(2))
        Set highNrRow = Columns(2).Find(highNr)
    MsgBox "The highest number starts at row " & highNrRow.Row - (highNr - 1)
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top