Hello
I have a lot of workbooks, which have to be decomposed in the same way.
I have the ollowing code to insert new rows when the value in column B changes and insert text into those rows:
Sub InsertRowsV2()
Dim lastRow As Long
Dim rowPtr As Long
Dim strT1 As String
Dim strT2 As String
strT1 = "Begin-Total"
strT2 = "End-Total"
lastRow = Range("B" & Rows.Count).End(xlUp).Row
Range("B" & lastRow + 1).Value = strT2
For rowPtr = lastRow To 3 Step -1
If Range("B" & rowPtr) <> Range("B" & rowPtr - 1) Then
Range("B" & rowPtr).Resize(2).EntireRow.Insert
Range("B" & rowPtr).Value = strT2
Range("B" & rowPtr + 1).Value = strT1
End If
Next rowPtr
Range("B2").Resize(2, 1).EntireRow.Insert
Range("B2").Resize(2, 1).EntireRow.Interior.ColorIndex = xlNone
Range("B3").Value = strT1
End Sub
However, I now have to CONCATENATE the values between the inserted rows, because in column A I have different numbers, and I have to take the lowest number and the highest number in between those rows and copy paste it to the cell next to the strings (Begin-total and end-total), so that would be in column C in this example.
I have attached a little example...
Bookmarks