Hi All,
I have this code which adds blank rows at points on a table where names change over from one to the next.
This code works fine between row 4 and the last row but I have struggled to get it to work between row 4 and the second to last row, adding this stops a blank row being introduce just before the totals row.
Also, I need to find each of the new empty cells in column B and copy and paste into it the value from the cell below and to the left - column A. For example for new empty cell B10 the value to be copied and pasted into it would be taken from cell A11 so on and so forth.
Any help or pointers would be very much appreciated
I have this code which adds blank rows at points on a table where names change over from one to the next.
HTML:
Bob
Bob
New blank row here
Anne
Anne
New blank row here
etc
etc
etc
Tom
Tom
Total
Note - No new row between Tom and total
Code:
Sub InsertRowsAtValueChangeColumnB()
Dim X As Long, LastRow As Long
Const DataCol As String = "A"
Const StartRow = 4
LastRow = Cells(Rows.Count, DataCol).End(xlUp).Row
Application.ScreenUpdating = False
For X = LastRow To StartRow + 1 Step -1
If Cells(X, DataCol).Value <> Cells(X - 1, DataCol) Then Rows(X).Insert
Next
Application.ScreenUpdating = True
End Sub
This code works fine between row 4 and the last row but I have struggled to get it to work between row 4 and the second to last row, adding this stops a blank row being introduce just before the totals row.
Also, I need to find each of the new empty cells in column B and copy and paste into it the value from the cell below and to the left - column A. For example for new empty cell B10 the value to be copied and pasted into it would be taken from cell A11 so on and so forth.
Any help or pointers would be very much appreciated