VBA Excel compare sheet with highlight of the changed data

Hi,

I have found this code and done some minor changes to it, and would very much like to add a simple yet needed feature to it, when showing the changes in the sheet "Resultat" i would very much like to see which cell the changes is in with a highlighted colored cell, just like in conditional formating, how do i do this?

I'm sorry im very new to VBA and still learning

here is the code i'm using:

Private Sub CopyExceptionSheet_Click()

Dim r1 As Range, r2 As Range, r3 As Range

With Sheets("Data_in")
    Set r1 = .Range("A1:E1", .Range("A" & Rows.Count).End(xlUp))
End With

With Sheets("Old_data")
    Set r2 = .Range("A1:E1", .Range("A" & Rows.Count).End(xlUp))
End With

Sheets("Resultat").Range("1:" & Rows.Count).EntireRow.Delete
LastRow = 0
For Each r3 In r1
    Dim rng1 As Range
    Set rng1 = r2.Find(What:=r3.Value, After:=r2.Cells(1), LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False)
    If rng1 Is Nothing Then
       LastRow = LastRow + 1
       r3.EntireRow.Copy Sheets("Resultat").Range("A" & LastRow)
       'Sheets("Sheet3").Range("A" & LastRow).Value = r3.Value
    End If
Next r3

For Each r3 In r2
    Dim rng2 As Range
    Set rng2 = r1.Find(What:=r3.Value, After:=r1.Cells(1), LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False)
    If rng2 Is Nothing Then
       LastRow = LastRow + 1
       r3.EntireRow.Copy Sheets("Resultat").Range("A" & LastRow)
       'Sheets("Sheet3").Range("A" & LastRow).Value = r3.Value
    End If
Next r3

MsgBox "Samligning Kørt - se sheetet 'Resultat'"

End Sub

Open in new window

LVL 1
HakumAsked:
Who is Participating?
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.

Rgonzo1971Commented:
Hi,

pls try

Private Sub CopyExceptionSheet_Click()

Dim r1 As Range, r2 As Range, r3 As Range

With Sheets("Data_in")
    Set r1 = .Range("A1:E1", .Range("A" & Rows.Count).End(xlUp))
End With

With Sheets("Old_data")
    Set r2 = .Range("A1:E1", .Range("A" & Rows.Count).End(xlUp))
End With

Sheets("Resultat").Range("1:" & Rows.Count).EntireRow.Delete
LastRow = 0
For Each r3 In r1
    Dim rng1 As Range
    Set rng1 = r2.Find(What:=r3.Value, After:=r2.Cells(1), LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False)
    If rng1 Is Nothing Then
       LastRow = LastRow + 1
       r3.EntireRow.Copy Sheets("Resultat").Range("A" & LastRow)
       Sheets("Resultat").Cells(LastRow, r3.Column).Interior.Color = vbYellow
       'Sheets("Sheet3").Range("A" & LastRow).Value = r3.Value
    End If
Next r3

For Each r3 In r2
    Dim rng2 As Range
    Set rng2 = r1.Find(What:=r3.Value, After:=r1.Cells(1), LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False)
    If rng2 Is Nothing Then
       LastRow = LastRow + 1
       r3.EntireRow.Copy Sheets("Resultat").Range("A" & LastRow)
       Sheets("Resultat").Cells(LastRow, r3.Column).Interior.Color = vbYellow
       'Sheets("Sheet3").Range("A" & LastRow).Value = r3.Value
    End If
Next r3

MsgBox "Samligning Kørt - se sheetet 'Resultat'"

End Sub

Open in new window

Regards
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
HakumAuthor Commented:
Awesome!! thank you sooo much!!! it works like a charm :)
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
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.