Inserting Row if variables are met

December 31, 2008 at 14:04:40
Specs: Windows XP, Pentium(R) 4CPU 3.00GHz 2
I have a spreadsheet with over 2000 lines of data. Column C has my data of interest. Several lines of the data are the same, then it changes to a new number...I need to know the easiest way to insert a blank Row where those numbers change other than me changing it all manually...Any ideas? Mentally my mind was thinking If c1 equals c2 then go to the next row...but if it doesn't equal then insert a row....

See More: Inserting Row if variables are met

Report •

January 1, 2009 at 19:24:06
Assuming your first piece of data is in C1 and the last is in C2000, try this code:

Sub Insert_Rows()
Rw = 1
LastRow = 2000
If Cells(Rw, "C") <> Cells(Rw + 1, "C") Then
Rows(Rw + 1).EntireRow.Insert
Rw = Rw + 1
NewRow = NewRow + 1
End If
If Rw = LastRow + NewRow Then Exit Sub
Rw = Rw + 1
GoTo NxtChk
End Sub

Report •
Related Solutions

Ask Question