VBA - Before After macro

Hi

I have a Excel file with 3 sheets:
Before
After
Recap

I need to validate the differences between the Before and After sheet and put transfer the results in sheet called  Recap.

In attachment, if you look at sheet Before in the Test4 column, you will see some values. I need to search for the values not showing in sheet After in the same column and transfer the values missing in the sheet Recap column A starting at Row 2 going down.

I need to also do the same thing with Sheet After column Test 4 not showing in Sheet Before column Tes4. Result of missing value will go into Recap column B.

How can i do that?

In attachment you will have a sample and the final result i should get in the Recap sheet.
Thanks
before-after.xlsm
LVL 11
Wilder1626Asked:
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.

Saurabh Singh TeotiaCommented:
Their you go run this code...

Private Sub CommandButton1_Click()
    Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet
    Dim rng As Range, cell As Range, r As Range
    Dim lrow As Long, lr As Long, lr1 As Long

    Set ws = Sheets("Before")
    Set ws1 = Sheets("After")
    Set ws2 = Sheets("Recap")

    lr1 = ws2.Cells(Cells.Rows.Count, "A").End(xlUp).Row

    If lr1 > 1 Then ws2.Range("A2:A" & lr1).Clear

    lr1 = ws2.Cells(Cells.Rows.Count, "B").End(xlUp).Row

    If lr1 > 1 Then ws2.Range("B2:B" & lr1).Clear


    lrow = ws.Cells(Cells.Rows.Count, "d").End(xlUp).Row
    Set rng = ws.Range("D2:D" & lrow)

    lr = ws1.Cells(Cells.Rows.Count, "d").End(xlUp).Row
    Set r = ws1.Range("D2:D" & lr)


    For Each cell In rng

        If Application.WorksheetFunction.CountIf(r, cell.Value) = 0 Then

            lr1 = ws2.Cells(Cells.Rows.Count, "a").End(xlUp).Row + 1

            ws2.Cells(lr1, 1).Value = cell.Value

        End If

    Next cell



    For Each cell In r

        If Application.WorksheetFunction.CountIf(rng, cell.Value) = 0 Then

            lr1 = ws2.Cells(Cells.Rows.Count, "b").End(xlUp).Row + 1

            ws2.Cells(lr1, 2).Value = cell.Value

        End If

    Next cell

End Sub

Open in new window


Your workbook for your reference...

Saurabh...
before-after.xlsm
0

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:
Thanks for your help. This is what i was looking for.
0
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.