Comparing and finding differences in rows with multiple columns between two worksheets

MariosB

New Member
Joined
Feb 23, 2014
Messages
26
I'm not sure if this has been answered before but I've been looking for an answer to this and couldn't find one. Maybe someone can help me

This is Sheet1 containing client details
ID
Name
Address
Telephone
Position
1111
ClientA
Street1
111
Pos1
2222
ClientB
Street2
222
Pos2
3333
ClientC
Street3
333
Pos3
4444
ClientD
Street4
444
Pos4

<tbody>
</tbody>









This is Sheet2 that I get from colleagues that may have added or removed clients, containing their updated details and not in the same position (I made the changes in Bold)
ID
Name
Address
Telephone
Position
2222
ClientB
Street23
2323
Pos2
1111
ClientA
Street1
666
Pos1
4444
ClientD
Street8
444
Pos8
5555
ClientE
Street5
555
Pos5

<tbody>
</tbody>









I want to be able to compare all of the details of clientA (address,tel,pos etc) from Sheet1 with those from Sheet2 and highlight the differences. So in essence I want to compare one row from Sheet1 with another row from Sheet2 with all the data from all 5 columns. I hope this is clear and any help is much appreciated!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hiker95

I dont wanna be picky, the module works just great but one small 'problem' I found is that data that is present in MARCH and not in MARCH2 are not highlighted. As you can see from the example, ClientC is not highlighted. Is there anyway to fix this?

thanks!
MariosB
 
Upvote 0
MariosB,

I dont wanna be picky, the module works just great but one small 'problem' I found is that data that is present in MARCH and not in MARCH2 are not highlighted. As you can see from the example, ClientC is not highlighted. Is there anyway to fix this?

Based on your instructions, we are comparing the data in March2 to the data in March,
and, my screenshots, my latest macro works correctly.


Should the macro also compare March to March2?
 
Upvote 0
MariosB,

Sample raw data worksheets before the macro:


Excel 2007
ABCDEFU
1IDNameAddressTelephonePosition
21111ClientAStreet1111Pos1
32222ClientBStreet2222Pos2
43333ClientCStreet3333Pos3
54444ClientDStreet4444Pos4
6
MARCH



Excel 2007
ABCDEFU
1IDNameAddressTelephonePosition
22222ClientBStreet232323Pos2
31111ClientAStreet1666Pos1
44444ClientDStreet8444Pos8
55555ClientEStreet5555Pos5
6
MARCH2


And, after the NEW macro:


Excel 2007
ABCDEFU
1IDNameAddressTelephonePosition
21111ClientAStreet1111Pos1
32222ClientBStreet2222Pos2
43333ClientCStreet3333Pos3
54444ClientDStreet4444Pos4
6
MARCH



Excel 2007
ABCDEFU
1IDNameAddressTelephonePosition
22222ClientBStreet232323Pos2
31111ClientAStreet1666Pos1
44444ClientDStreet8444Pos8
55555ClientEStreet5555Pos5
6
MARCH2


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Option Explicit
Sub CompareTwoSheets()
' hiker95, 02/25/2014, ME759656
Dim d As Range, c As Long, lc As Long
Dim idrng As Range
With Sheets("MARCH2")
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  For Each d In .Range("C2", .Range("C" & Rows.Count).End(xlUp))
    Set idrng = Sheets("MARCH").Columns(3).Find(d.Value, LookAt:=xlWhole)
    If idrng Is Nothing Then
      .Range(.Cells(d.Row, 3), .Cells(d.Row, lc)).Interior.Color = 255
    ElseIf Not idrng Is Nothing Then
      For c = 3 To lc
        If .Cells(d.Row, c).Value <> Sheets("MARCH").Cells(idrng.Row, c).Value Then
          .Cells(d.Row, c).Interior.Color = 255
          Sheets("MARCH").Cells(idrng.Row, c).Interior.Color = 255
        End If
      Next c
    End If
  Next d
End With
With Sheets("MARCH")
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  For Each d In .Range("C2", .Range("C" & Rows.Count).End(xlUp))
    Set idrng = Sheets("MARCH2").Columns(3).Find(d.Value, LookAt:=xlWhole)
    If idrng Is Nothing Then
      .Range(.Cells(d.Row, 3), .Cells(d.Row, lc)).Interior.Color = 255
    ElseIf Not idrng Is Nothing Then
      For c = 3 To lc
        If .Cells(d.Row, c).Value <> Sheets("MARCH2").Cells(idrng.Row, c).Value Then
          .Cells(d.Row, c).Interior.Color = 255
          Sheets("MARCH2").Cells(idrng.Row, c).Interior.Color = 255
        End If
      Next c
    End If
  Next d
End With
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the CompareTwoSheets macro.
 
Upvote 0
Thanks for the help Markmzz!

Hi MariosB,

Try this with Excel 2007:

Created the names:

myID - Refers To: =MARCH!$A$2:$A$343

myID2 - Refers To: =MARCH2!$A$2:$A$333

Formulas - conditional formatting

Code:
In the range A2:E343 of the sheet MARCH

=IFERROR(INDEX(OFFSET(myID2,,COLUMNS($A2:A2)-1),MATCH($A2,myID2,0),)<>A2,1)

And

In the range A2:E333 of the sheet MARCH2

=IFERROR(INDEX(OFFSET(myID,,COLUMNS($A2:A2)-1),MATCH($A2,myID,0),)<>A2,1)

Markmzz
 
Upvote 0
Once again thank you hiker95 and Markmzz. Both of your solutions work just great! Will definately come to you again for anything else if needed :D
 
Upvote 0
MariosB,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0
Hi MariosB,

I'm happy that your problem was solved and thank you for providing feedback.

Markmzz
 
Upvote 0

Forum statistics

Threads
1,215,334
Messages
6,124,325
Members
449,154
Latest member
pollardxlsm

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