Insert row between different item

  • Thread starter Thread starter A guy
  • Start date Start date
A

A guy

Dear all,

Please see the following data:

Part no. Loacation Date
637A A1 10-MAY-2004
807K B1 11-MAY-2004
639A B2 12-MAY-2004
807K C1 12-MAY-2004
807K D1 15-MAY-2004


How can I use macro or function to sort the data by part
no. and then insert a row between each different part no
automatically. Like the below result:

Part no. Loacation Date
637A A1 10-MAY-2004

639A B2 12-MAY-2004

807K B1 11-MAY-2004
807K C1 12-MAY-2004
807K D1 15-MAY-2004
 
do it manually and record it in a new macro
Tools -> Macro -> Record new macro

open the new macro and edit to your suit
Tools -> Macro -> Macros -> Edit
 
Try

Sub InsertRow()
Dim lRow As Long

For lRow = Range("a" & Rows.Count).End(xlUp).Row To 2 Step -1
If Cells(lRow - 1, "a").Value <> "" And Cells(lRow, "a").Value <
"" Then
If Cells(lRow, "a").Value <> Cells(lRow - 1, "a") Then
Rows(lRow).Insert
End If
End If
Next lRow
End Su
 

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

Back
Top