Adding a line

nikneven

Board Regular
Joined
Mar 20, 2006
Messages
117
ok, here is my (i didn't write it, just using it) macro to search my data and if columns E and then f and insert two blank rows between each. for example, F is the last name and E is the first. I now have two blank lines inbetween people, even if they have the same last name.

Code:
Sub DTS9()
Dim i As Long
For i = Range("a" & Rows.Count).End(xlUp).Row To 2 Step -1
If Cells(i, 6) <> "" And Cells(i, 6) <> Cells(i + 1, 6) Or Cells(i, 5) <> Cells(i + 1, 5) Then
Cells(i + 1, 6).EntireRow.Insert Shift:=xlDown
Cells(i + 1, 6).EntireRow.Insert Shift:=xlDown
End If
Next
End Sub

How do i mod the macro so that after it inserts a copy of row 1 after the two blank lines?
so it would look like this:

same name
same name
blank row
blank row
copy of row 1
diff name
diff name
blank row
blank row
copy of row 1
third name
third name.


Thanks
Nik
 
hi nik.

try this out:

Code:
Sub DTS9()
    Dim i As Long
    
    For i = Range("a" & Rows.Count).End(xlUp).Row To 2 Step -1
        With Cells(i, 6)
            If .Value <> "" And .Value <> .Offset(1, 0).Value _
                Or .Offset(0, -1).Value <> .Offset(1, -1).Value Then
                
                For j = 1 To 3
                    .Offset(1, 0).EntireRow.Insert Shift:=xlDown
                Next j
                
                Range("E1:F1").Copy
                .Offset(3, -1).PasteSpecial
            End If
        End With
    Next
End Sub

cheers. ben.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top