Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script to insert row in excel

Status
Not open for further replies.

ToneSta

Technical User
Jun 17, 2003
5
AU
I have a group of data that is sorted by the values in the first column. eg:

AD ADM 900
AD BXB 800
BR ABC 500
BR DCA 600

I need to run a macro of some sort that will detect a change in the value of a cell in the first column (when reading down from the top of the range to the bottom) and insert a row at the value change (i.e between AD and BR).

Does anyone know how this could be achieved?
Thanks
 
This sub should do it
-------------------------------------

Sub insert_rows()

Dim r As Integer
r = 2
Cells(2, 1).Select
Do While Cells(r, 1) <> &quot;&quot;
If Cells(r, 1) <> Cells(r - 1, 1) Then
Cells(r, 1).Select: Selection.EntireRow.Insert: r = r + 2
Else
r = r + 1
End If
Loop

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top