insert row with logic

T

TJ

Hi,

I am using the below script but don't how to modify it or if anyone can
suggest anything else to include condition that if the subequent row is the
same then it should skip inserting blank rows where in the colmun the data is
duplicated.

-------------------------------------------------------------------------
Sub test()
Application.ScreenUpdating = False
Dim R As Long
Dim rng As Range
Set rng = ActiveSheet.UsedRange
For R = rng.Rows.Count To 1 Step -1
rng.Rows(R + 1).Resize(1).EntireRow.Insert
Next R
Application.ScreenUpdating = True
End Sub
 
G

Gord Dibben

Try this one.

Sub InsertRow_At_Change()
'Sandy Mann July 1st, 2007
Dim LastRow As Long
Dim X As Long
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
For X = LastRow To 2 Step -1
If Cells(X, 1).Value <> Cells(X - 1, 1).Value Then
If Cells(X, 1).Value <> "" Then
If Cells(X - 1, 1).Value <> "" Then
Cells(X, 1).entirerow.Insert Shift:=xlDown
End If
End If
End If
Next X
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP
 
D

Dana DeLouis

Cells(X, 1).entirerow.Insert Shift:=xlDown

Just an idea for the above line...

Rows(X).Insert

= = = =
Dana DeLouis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top