ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Count between Values (https://www.excelbanter.com/excel-programming/344372-count-between-values.html)

smandula

Count between Values
 
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



Bob Phillips[_6_]

Count between Values
 
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)


"smandula" wrote in message
...
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





smandula

Count between Values
 
Thanks a lot!!
Works perfectly

Thanks Again
Steve




stringstroker62

Count between Values
 
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



All times are GMT +1. The time now is 05:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com