Count between Values

  • Thread starter Thread starter smandula
  • Start date Start date
S

smandula

I would you count zero values between real values inclusive?
Hopefully in VBA
Such as:

A B C
1 2
2 0
3 0
4 1 count 4
5 1
6 0
7 1 count 3
8 1
9 1 count 2
10 8
11 0
12 2 count 3

With Thanks
Steve
 
Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim iStart As Long

iLastRow = Cells(Rows.Count, "B").End(xlUp).Row
iStart = 1
For i = 2 To iLastRow
If Cells(i, "B").Value <> 0 Then
Cells(i, "C").Value = i - iStart + 1
iStart = i + 1
i = i + 1
End If
Next i

End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)
 
R = 1

Do While Cells(R, 1) <> ""

ZeroCnt = 0
Flag = 0

Do While Cells(R, 2) = 0
ZeroCnt = ZeroCnt + 1
R = R + 1
Flag = 1
Loop

If Flag = 0 Then R = R + 1
If Flag = 1 Then Cells(R, 3) = "count " & ZeroCnt + 2

Loop
 
Back
Top