Find Discripency Excel

Hi,
Please find attached the excel file i am working.

I need a macro to do the below task.

if order no (COL B) is same and Invoice No (COL I) is same then check whether Invoice Line Nos (COl J) is in order and not missing say for example it should be like 1, 2, 3, 4 etc..

i only need to check whether if it is 1, 3, 4 order or like that where one or many number is missing from the sequence. Please help.
Test.xlsx
LVL 9
suvmitraAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wchhCommented:
Try macro below
Sub check()

    ActiveSheet.Select
    Range("B3").Select
    Do Until Selection.Value = ""
       If Selection.Value = Selection.Offset(-1, 0).Value And _
          Selection.Offset(0, 7).Value = Selection.Offset(-1, 7).Value Then
          
       If Selection.Offset(0, 8).Value <> Selection.Offset(-1, 8).Value + 1 Then
          Selection.Offset(0, 8).Interior.Color = 255
       Else
          Selection.Offset(0, 8).Interior.Color = xlNone
       End If
       Else
       Selection.Offset(0, 8).Interior.Color = xlNone
       End If
       Selection.Offset(1, 0).Select
    Loop

End Sub

Open in new window

Saqib Husain, SyedEngineerCommented:
Enter this formula in O2 and copy down. This will solve your problem in a very simple way.

=IF(J2=1,"",IF(SUMPRODUCT(($A$2:$A$9=A2)*($I$2:$I$9=I2)*($J$3:$J$10=J2-1))=0,"Previous record missing",""))

if you have more rows you can adjust the 9 in the formula to whatever you have.

Saqib

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
suvmitraAuthor Commented:
I have tried some samples and find ssaqibh ' solution is providing more correct result..in different situations. Thank you all.
suvmitraAuthor Commented:
is it possible to have a VBA code for this formula ... also I think we should take reference for B column not A column ..pls let me know. Thanks.

=IF(J2=1,"",IF(SUMPRODUCT(($A$2:$A$9=A2)*($I$2:$I$9=I2)*($J$3:$J$10=J2-1))=0,"Previous record missing",""))
Saqib Husain, SyedEngineerCommented:
Try this sub

Sub polulateformula()
lr = ActiveSheet.Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row
ActiveSheet.Range("O2:O" & lr).FormulaR1C1 = _
"=IF(RC[-5]=1,"""",IF(SUMPRODUCT((R2C2:R" & lr & "C2=RC[-13])*(R2C9:R" & lr & "C9=RC[-6])*(R2C10:R" & lr & "C10=RC[-5]-1))=0,""Previous record missing"",""""))"
End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.