MATCH alternative

mirusev

New Member
Joined
Oct 14, 2018
Messages
20
Office Version
  1. 365
Platform
  1. Windows
That MATCH() does what I need - finding series of ones, but when rows exceed 300 000 it stuck.
Do I need to split the raw data on 300k rows?
What is the better alternative to get these results (if any)? In fact I need it for few millions of rows.

Thanks!

check-500k.xlsx
CD
112
211
300
400
511
600
700
812
911
1000
Sheet1
Cell Formulas
RangeFormula
C1:C10C1=IF(B1>=$F$1,0,1)
D1:D10D1=MATCH(0,C1:C260000,0)-1
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
In fact I need it for few millions of rows.
Not sure how you are going to deal with that since Excel only has 1,048,576 rows.

Still up to about that you could try this

20 07 26.xlsm
CD
112
211
300
400
511
600
700
812
911
1000
Match
Cell Formulas
RangeFormula
D1:D10D1=MATCH(0,C1:C$1048576,0)-1
 
Upvote 0
It is OK to be up to 1,048,576 rows, I will split it on 3. But it can not pass more than 300 max 400 000 rows. Excel just stops :( and/or crashes
It is on i7 with 16 GB (still has free memory when run), installed the 64 bits version, but the problem remains, so may be another approach is the solution, not that based on MATCH()
 
Upvote 0
You could try this macro instead

VBA Code:
Sub Count_Ones()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long, fr As Long
  
  a = Range("C1", Range("C" & Rows.Count).End(xlUp).Offset(1)).Value
  ReDim b(1 To UBound(a) - 1, 1 To 1) As Long
  Do
    i = i + 1
    If a(i, 1) = 1 Then
      fr = i
      Do
        k = k + 1
      Loop Until a(i + k, 1) = 0
      For j = 1 To k
        b(fr + j - 1, 1) = k - j + 1
      Next j
      i = i + k - 1
      k = 0
    End If
  Loop Until i >= UBound(a)
  Range("D1").Resize(UBound(b)).Value = b
End Sub
 
Upvote 0
There's a way to do it using 2 columns and simple formulae. I tested it with a million rows and it calculated quickly.

Book1
ABC
5000
6111
7000
8000
9155
10140
11130
12120
13110
14000
15122
16110
Sheet2
Cell Formulas
RangeFormula
B5:B16B5=IF(A5=1,B6+1,0)
C5:C16C5=IF(B4=0,B5,0)
 
Upvote 0
You could try this macro instead

VBA Code:
Sub Count_Ones()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long, fr As Long
 
  a = Range("C1", Range("C" & Rows.Count).End(xlUp).Offset(1)).Value
  ReDim b(1 To UBound(a) - 1, 1 To 1) As Long
  Do
    i = i + 1
    If a(i, 1) = 1 Then
      fr = i
      Do
        k = k + 1
      Loop Until a(i + k, 1) = 0
      For j = 1 To k
        b(fr + j - 1, 1) = k - j + 1
      Next j
      i = i + k - 1
      k = 0
    End If
  Loop Until i >= UBound(a)
  Range("D1").Resize(UBound(b)).Value = b
End Sub


Totally amazing!!! I love you! :)
 
Upvote 0
There's a way to do it using 2 columns and simple formulae. I tested it with a million rows and it calculated quickly.

Book1
ABC
5000
6111
7000
8000
9155
10140
11130
12120
13110
14000
15122
16110
Sheet2
Cell Formulas
RangeFormula
B5:B16B5=IF(A5=1,B6+1,0)
C5:C16C5=IF(B4=0,B5,0)

Also great alternative! Highly appreciated! Thank you :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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