ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trying to add a row after the last value and count (https://www.excelbanter.com/excel-programming/276525-trying-add-row-after-last-value-count.html)

TRexSuz

Trying to add a row after the last value and count
 
I have a collumn with several matching values sorted. i.e. e4-e10 all =
6, e11-e20 all = 5, etc. The number of values will vary. I want to find
the last "6" and add a row below it and then count the number of 6's in
that range and so on and so on.

Ronald Dodge

Trying to add a row after the last value and count
 
Dim cell as Range, CurVal as Long, CurCount as Long, LastRow as Long, I as
Long
CurVal = Range("E4").Value
CurCount = 1
LastRow = Range("E65536").End(xlUp).Row
For I = 5 to LastRow Step 1
If CurVal = Range("E" & I).Value Then
CurCount = CurCount + 1
Else
CurVal = Range("E" & I)
Range(I & ":" & I).Insert
I = I + 1
LastRow = LastRow + 1
Range("E" & I).Value = CurCount
CurCount = 0
End If
Next I

--
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"TRexSuz" wrote in message
...
I have a collumn with several matching values sorted. i.e. e4-e10 all =
6, e11-e20 all = 5, etc. The number of values will vary. I want to find
the last "6" and add a row below it and then count the number of 6's in
that range and so on and so on.





All times are GMT +1. The time now is 07:32 PM.

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