VBA - Comparison between 2 sheets

I’m trying to do a comparison between 2 sheets Before and After on column C,G,M.
If on a row, I have a combination of the 3 columns from sheet Before, not showing in the sheets After, it would transfer the 3 columns values into sheet: Recap in column A, B and C.
The thing to remember is that each combinations will not automatically be on the same row of the other sheet, so the macro needs to look at all combinations and see it it exist in the other sheets. If it doesn’t, then it transfer the 3 values in the sheet Recap.
How can I do that?

Thanks for your help
Sheet Before:
Sheet: After
Sheet Recap
LVL 11
Who is Participating?

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

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.

Saurabh Singh TeotiaCommented:
Just to rephrase if i understand correctly you want to look from sheet after to sheets before as the combination will be on the same row and if you don't find that combination..then you want to move that value in sheet recap...
Wilder1626Author Commented:

I want to look from sheet after to sheets before and see if any of the combination from Sheet Before don't show in Sheet After. If there is same combinations in both sheets, it may not be on the same row from both sheets, and you may also have duplicate rows with the same combinations.

If you found combinations from Sheet Before that is not in Sheet After, the combination for the sheet before should show in sheet RECAP.

But both sheet Before and After needs to stay the way they are. I don't want to remove data from both sheets.
Saurabh Singh TeotiaCommented:
But in your example worksheet you showing the data from after sheet..so if i understand correctly...you want to move data from before sheet to recap sheet on the combination which you don't find in after worksheet?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Wilder1626Author Commented:
you are correct, sorry, i've put the wrong Recap snap shot. But still i would need that option also.
Saurabh Singh TeotiaCommented:
Okay so if i give you a option by you can choose like if you choose yes macro will move data from before to recap and if you choose no macro will move data from after to recap..will that do??
Wilder1626Author Commented:
this looks like a very good option. Yes, that will do. Thanks
Saurabh Singh TeotiaCommented:
Their you go use this code..this will do what you are looking for...

Private Sub CommandButton1_Click()
    Dim str As String
    Dim r As Range, r1 As Range, r2 As Range
    Dim rng As Range, cell As Range
    Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet
    Dim lr As Long, lr1 As Long
    Dim mr As Long, ch As Long

    str = MsgBox("Yes will Copy Data from Before and No from After to recap", vbYesNo, "Please Choose")
    If str = vbYes Then
        Set ws = Sheets("Before")
        Set ws1 = Sheets("After")
        Set ws = Sheets("After")
        Set ws1 = Sheets("Before")

    End If

    lr = ws.Cells.Find(what:="*", searchorder:=xlRows, searchdirection:=xlPrevious).Row
    lr1 = ws1.Cells.Find(what:="*", searchorder:=xlRows, searchdirection:=xlPrevious).Row

    Set r = ws1.Range("C2:C" & lr1)
    Set r1 = ws1.Range("G2:G" & lr1)
    Set r2 = ws1.Range("M2:M" & lr1)

    Set rng = ws.Range("C2:C" & lr)

    Set ws2 = Sheets("Recap")
    mr = ws2.Cells.Find(what:="*", searchorder:=xlRows, searchdirection:=xlPrevious).Row

    If mr > 1 Then ws2.Range("A2:C" & mr).ClearContents

    For Each cell In rng

        ch = Application.Evaluate("=SumProduct((" & ws1.Name & "!" & r.Address & "=""" & cell.Value & """)*(" & ws1.Name & "!" & r1.Address & "=" & cell.Offset(0, 4).Value & ")*(" & ws1.Name & "!" & r2.Address & "=""" & cell.Offset(0, 10).Value & """))")
        If ch = 0 Then
            mr = ws2.Cells.Find(what:="*", searchorder:=xlRows, searchdirection:=xlPrevious).Row + 1
            ws.Range("C" & cell.Row & ",G" & cell.Row & ",M" & cell.Row).copy ws2.Range("A" & mr)
        End If
    Next cell

End Sub

Open in new window

Your workbook...

Wilder1626Author Commented:
I did some test, but i'm facing a problem depending on what type of data i have in the cells

Can you please look at this attachment?
Saurabh Singh TeotiaCommented:
Their you go use this...


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
Wilder1626Author Commented:
This is very good. Exactly what i needed. Thanks a lot for your help.
@Saurabh Singh Teotia: Your solution is great!
However I was wondering if there is a way to dynamically find the mismatch between before and after sheet.

I was thinking about a parameter table in which you specify:
some information:

Based on this information the macro should automatically read parameter sheet and ouput in recap all the mismatch values.

That means if I add a field in the comparison it should be take into account in the recap.

Additionnally is there a way to have in the recap the information of both sheets After and Before in order to see the difference?

Thank you very much for your help.
Saurabh Singh TeotiaCommented:
Hey LD16,

I'm still not clear at the end of the day what you are looking for and trying to solve..Can you open a question for the same and point me to that ..Will be more then happy to work with you to solve the same.

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.