SUM/COUNT of Value 1 at the Start of Set

ibmy

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

How to get result in Column L (Start) ?

Start Assign.xlsb
GIL
1DataEndStart
2
315
41
51
61
715
8
9111
10
11
1212
1312
14
15
16111
17
18
1912
2012
21
2213
231
2413
25
26
27
090621

For Column I ( End) , I use this code :

VBA Code:
Sub End2()
  Dim a As Variant, b As Variant
  Dim i As Long, k As Long
  
  a = Range("G2", Range("G" & Rows.Count).End(xlUp).Offset(1)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 2 To UBound(a)
    If a(i, 1) = 1 Then
      k = k + 1
    Else
      If a(i - 1, 1) = 1 Then
        b(i - 1, 1) = k
        k = 0
      End If
    End If
  Next i
  Range("I2").Resize(UBound(b)).Value = b
End Sub

Column G ( Data) contain value 1 and blank cell.
Real data is 200k-250k row.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Would this do the job for you?

VBA Code:
Sub Start2()
    Dim lr As Long: lr = Range("G" & Rows.Count).End(xlUp).Row
    Dim i As Long
    Dim v As Long: v = 0
    
    For i = lr To 2 Step -1
        If v = 0 Then
            If Range("I" & i).Value > 0 Then
                v = Range("I" & i).Value
            End If
            If Range("G" & i).Offset(-1).Value = "" Or Range("G" & i).Offset(-1).Value = "Data" Then
                If v <> 0 Then Range("L" & i).Value = v
                v = 0
            End If
        Else
            If Range("G" & i).Offset(-1).Value = "" Or Range("G" & i).Offset(-1).Value = "Data" Then
                If v <> 0 Then Range("L" & i).Value = v
                v = 0
            End If
        End If
    Next i
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

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