Inseart row if cell number is repeating

J

JoeM

Hi

I have a data sheet, which is a sales data which contains item
particulars. each invoice contains one or more items. many of them is
single item which ends in single row. if more items are there, it
comes in different rows. i want to inseart one row each if the invoice
number is repeating to two three up to 20 rows. new row need to come
top of the cell number

1 rice 10 kg
27.00 270.00
2 oil 3 kl
80-00 240.00
3 Rice 5 kg
33.00 165.00
3 oil 1 kl
80.00 80.00
4 Salt 1 kg
10.00 10.00


the invoce number (cell number) "first column" 3 is repeating twice.

1 rice 10 kg
27.00 270.00
2 oil 3 kl
80-00 240.00

3 Rice 5 kg
33.00 165.00
3 oil 1 kl
80.00 80.00
4 Salt 1 kg
10.00 10.00


i insearted one row after cell number 2, anyonce can help to creat
one macro for this?(Inseart row with condition)


thanks

Jophy
 
B

Bob Phillips

Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

Application.ScreenUpdating = False

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow - 2 To 2 Step -1

If .Cells(i, "A").Value <> .Cells(i + 1, "A").Value And _
.Cells(i + 1, "A").Value = .Cells(i + 2, "A").Value Then

.Rows(i + 1).Insert
End If
Next i
End With

Application.ScreenUpdating = True

End Sub
 

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

Top