insert rows when cell above equals cell below


Posted by jim c on January 26, 2001 1:23 PM

I'm trying to automate the insertion of rows. Right now, I search for cell that doesn't match the one above it and insert 5 blank rows. Hard to explain...see example below...

A B C
1 18GA

2 18GA

3 16GA

4 16GA

5 14GA

When A3 does not equal A2, insert 5 blank rows
When A5 does not equal A4, insert 5 blank rows
So, in this illustration...I would click on row 3 and insert 5 rows, click on row 5 and insert 5 rows. TIA for any help.



Posted by Celia on January 26, 2001 7:11 PM


First select the range of cells and then run this:-

Sub Insert_Rows()
Dim x%, y%
y = Selection.Column
For x = Selection.Rows.Count To 2 Step -1
If Cells(x, y).Value <> Cells(x - 1, y).Value Then
Cells(x, y).EntireRow.Resize(5).Insert
End If
Next
End Sub

Celia