How to insert new row with dummy info if there is no sequence to item numbers

pyrte

New Member
Joined
Feb 16, 2016
Messages
7
Hi there,

I'm working on finding out missing orders in a bunch of sales records. I'm attaching a sample workbook here so that you can understand more of my requirements. Appreciate all the help you can provide.

The sales invoice denotes the sales invoice number at a material level. The item number denotes the line items in the sales invoice. If the sequence is broken then an item was deleted. I need a way to either through formula or macro to be able to find out these missing values, then add a row and fill it with the word deleted record. The item number is in an increment of 10 always. Each sales order item number will start with 10 with an increment of 10.

Looking forward to you guys help and support.

Sales InvoiceItem noMaterialCustomer
121212110125a1211A
12121212085a421A
12121213041a5a5A
121212140a45a15A
1212121501a54a5A
222213110a452a74B
222213120125a1212B
22221314085a422B
22221315041a5a6B
451243210a45a16C
4512432201a54a6C
451243230a452a75C
451243250125a1213C
45124326085a423C
45124328041a5a7C
451243290a45a17C
8747451101a54a7D
874745120a452a76D
874745130125a1214D
87474514085a424D
87474515041a5a8D
874745160a45a18D

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>

<tbody>
</tbody>
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Sales InvoiceItem noMaterialCustomerMARKER
121212110125a1211A
12121212085a421A#######
12121213041a5a5A
121212140a45a15A
1212121501a54a5A
222213110a452a74B
222213120125a1212B
22221314085a422BMnow all you need to do is run down col E and insert blank row where the M's are
22221315041a5a6B
451243210a45a16CI will post again with that macro in 5 minutes
4512432201a54a6C
451243230a452a75C
451243250125a1213CM
45124326085a423C
45124328041a5a7CM
451243290a45a17C
8747451101a54a7D
874745120a452a76D
874745130125a1214D
87474514085a424D
87474515041a5a8D
874745160a45a18D
#######
=IF(AND(A3=A2,B3-B2<>10),"M","")

<colgroup><col><col><col><col span="12"></colgroup><tbody>
</tbody>
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG20Jul34
[COLOR="Navy"]Dim[/COLOR] Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Num [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer,[/COLOR] R [COLOR="Navy"]As[/COLOR] Range
Lst = Range("A" & Rows.Count).End(xlUp).Row
[COLOR="Navy"]For[/COLOR] n = Lst To 2 [COLOR="Navy"]Step[/COLOR] -1
[COLOR="Navy"]With[/COLOR] Range("A" & n)
[COLOR="Navy"]If[/COLOR] Not .Offset(1) = "" And .Offset(1) = .Value [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]If[/COLOR] Not .Offset(1, 1).Value + 10 = .Offset(, 1) [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]If[/COLOR] (.Offset(1, 1).Value - .Offset(, 1)) / 10 > 1 [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]Set[/COLOR] R = .Offset(1).Resize(((.Offset(1, 1).Value - .Offset(, 1)) / 10) - 1)
            R.EntireRow.Insert
            R.Offset(-R.Rows.Count).Value = "Deleted Record"
        [COLOR="Navy"]End[/COLOR] If
   [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Sales InvoiceItem noMaterialCustomerMARKER
121212110125a1211A
12121212085a421A#######
12121213041a5a5A
121212140a45a15A
1212121501a54a5A
222213110a452a74B
222213120125a1212B
22221314085a422BMnow all you need to do is run down col E and insert blank row where the M's are
22221315041a5a6B
451243210a45a16CI will post again with that macro in 5 minutes
4512432201a54a6C
451243230a452a75C
For j = 3 To 100
451243250125a1213CM If Cells(j, 4) = "" Then GoTo 100
45124326085a423C If Cells(j, 5) = "M" Then GoTo 50 Else GoTo 75
50 Cells(j, 5).Select
45124328041a5a7CMSelection.EntireRow.Insert
451243290a45a17Cj = j + 1
8747451101a54a7D75 Next j
874745120a452a76D100 End Sub
874745130125a1214D
87474514085a424D
87474515041a5a8D
874745160a45a18D
easy to add lines into macro that put "deleted record into the new blank row
#######
=IF(AND(A3=A2,B3-B2<>10),"M","")

<colgroup><col><col><col><col span="12"></colgroup><tbody>
</tbody>
 
Upvote 0
Sales InvoiceItem noMaterialCustomerMARKER
121212110125a1211A
12121212085a421A#######
12121213041a5a5A
121212140a45a15A
1212121501a54a5A
222213110a452a74B
222213120125a1212B
THIS RECORD HAS BEEN DELETED
22221314085a422BMnow all you need to do is run down col E and insert blank row where the M's are
22221315041a5a6B
451243210a45a16CI will post again with that macro in 5 minutes
4512432201a54a6C
451243230a452a75C
THIS RECORD HAS BEEN DELETEDFINAL VERSION
451243250125a1213CM
45124326085a423CFor j = 3 To 100
THIS RECORD HAS BEEN DELETED If Cells(j, 4) = "" Then GoTo 100
45124328041a5a7CM If Cells(j, 5) = "M" Then GoTo 50 Else GoTo 75
451243290a45a17C50 Cells(j, 5).Select
8747451101a54a7DSelection.EntireRow.Insert
874745120a452a76DCells(j, 1) = "THIS RECORD HAS BEEN DELETED"
874745130125a1214Dj = j + 1
87474514085a424D75 Next j
87474515041a5a8D100 End Sub
874745160a45a18D
#######
=IF(AND(A3=A2,B3-B2<>10),"M","")
DELETED TEXT IS ON ONE ROW - HONEST

<tbody>
</tbody>
 
Last edited:
Upvote 0
Try this:-
Code:
[COLOR=Navy]Sub[/COLOR] MG20Jul34
[COLOR=Navy]Dim[/COLOR] Lst [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] n [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] Num [COLOR=Navy]As[/COLOR] [COLOR=Navy]Integer,[/COLOR] R [COLOR=Navy]As[/COLOR] Range
Lst = Range("A" & Rows.Count).End(xlUp).Row
[COLOR=Navy]For[/COLOR] n = Lst To 2 [COLOR=Navy]Step[/COLOR] -1
[COLOR=Navy]With[/COLOR] Range("A" & n)
[COLOR=Navy]If[/COLOR] Not .Offset(1) = "" And .Offset(1) = .Value [COLOR=Navy]Then[/COLOR]
    [COLOR=Navy]If[/COLOR] Not .Offset(1, 1).Value + 10 = .Offset(, 1) [COLOR=Navy]Then[/COLOR]
        [COLOR=Navy]If[/COLOR] (.Offset(1, 1).Value - .Offset(, 1)) / 10 > 1 [COLOR=Navy]Then[/COLOR]
            [COLOR=Navy]Set[/COLOR] R = .Offset(1).Resize(((.Offset(1, 1).Value - .Offset(, 1)) / 10) - 1)
            R.EntireRow.Insert
            R.Offset(-R.Rows.Count).Value = "Deleted Record"
        [COLOR=Navy]End[/COLOR] If
   [COLOR=Navy]End[/COLOR] If
[COLOR=Navy]End[/COLOR] If
[COLOR=Navy]End[/COLOR] With
[COLOR=Navy]Next[/COLOR] n
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick

This worked like a charm. Thank you so much for your support. I was really worried how I was going to handle something like for over 10 million records. You just saved me a whole deal of pain. You are simple awesome. I truly appreciate your help.
 
Upvote 0
Hi,

Here is another alternative.


Code:
Sub pyrte()
Dim i   As Long

For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
    If Cells(i, 1) = Cells(i - 1, 1) Then
       If (Cells(i, 2) - Cells(i - 1, 2)) / 10 > 1 Then
            Cells(i, 1).EntireRow.insert
            Cells(i, 1) = "Deleted Record"
        End If
    End If
Next
End Sub
 
Upvote 0
Thanks so much oldbrewer, Ombir and MickG. You all have been awesome support. I've learned so much and also solved a problem of having to review of over 1 million records.
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top