VB codes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am building a macro to compile a summary report based on some data file and would like to find out how to insert a blank row between differen code groups, e.g

Code group without break
1
1





Code group with break









Thank
J.C
 
Hi
try the following macro. It tests column A and inserts a blank row if
the values change
Sub insert_rows()
Dim lastrow As Long
Dim row_index As Long

lastrow = ActiveSheet.Cells(Rows.count, "A").End(xlUp).row
For row_index = lastrow - 1 To 1 Step -1
If Cells(row_index, "A").Value <> Cells(row_index + 1, "A").Value
Then
Cells(row_index + 1, "A").EntireRow.Insert (xlShiftDown)
End If
Next
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

J.C. said:
I am building a macro to compile a summary report based on some data
file and would like to find out how to insert a blank row between
differen code groups, e.g.
 
JC

One way:

Sub InsertLines()
Dim lastrow As Long
Dim i As Long
Application.ScreenUpdating = False
lastrow = Range("A" & Rows.Count).End(xlUp).Row
For i = lastrow To 3 Step -1
If Range("A" & i - 1) <> Range("A" & i) Then
Range("A" & i - 1).Offset(1, 0).EntireRow.Insert
End If
Next ' i
Application.ScreenUpdating = True
End Sub

Regards

Trevor


J.C. said:
I am building a macro to compile a summary report based on some data file
and would like to find out how to insert a blank row between differen code
groups, e.g.
 
Back
Top