insert row with logic

  • Thread starter Thread starter TJ
  • Start date Start date
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
 
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
 
Cells(X, 1).entirerow.Insert Shift:=xlDown

Just an idea for the above line...

Rows(X).Insert

= = = =
Dana DeLouis
 
Back
Top