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!
 
MariosB,

Sample raw data worksheets:


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



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


After the new macro in both worksheets:


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



Excel 2007
ABCDS
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 CompareW2toW1()
' hiker95, 02/23/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("A2", .Range("A" & Rows.Count).End(xlUp))
    Set idrng = Sheets("MARCH").Columns(1).Find(d.Value, LookAt:=xlWhole)
    If idrng Is Nothing Then
      .Range(.Cells(d.Row, 1), .Cells(d.Row, lc)).Interior.Color = 255
    ElseIf Not idrng Is Nothing Then
      For c = 2 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
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 CompareW2toW1 macro.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Maybe formulas. If yes, try this (with conditional formatting):

Code:
In MARCH sheet

=IFERROR(INDEX(MARCH2!B$2:B$333,MATCH($A2,MARCH2!$A$2:$A$333,0),)=B2,0)

And

In MARCH2 sheet

=IFERROR(INDEX(MARCH!B$2:B$343,MATCH($A2,MARCH!$A$2:$A$343,0),)=B2,0)

Markmzz
 
Upvote 0
Hiker95 thank you very very much!! It worked just great! You are awsome.

If I change my ID column to C (i leave A and B for personal usage) what do I have to change in the code?
 
Upvote 0
A small modification in my formulas:

Result

IDNameAddressTelephonePositionMARCH**IDNameAddressTelephonePositionMARCH2
1111ClientAStreet1111Pos12222ClientBStreet232323Pos2
2222ClientBStreet2222Pos21111ClientAStreet1111Pos1
3333ClientCStreet3333Pos34444ClientDStreet8444Pos8
4444ClientDStreet4444Pos45555ClientEStreet5555Pos5

<tbody>
</tbody>


Formulas - conditional formatting

Code:
In MARCH sheet

=IFERROR(INDEX(MARCH2!A$2:A$333,MATCH($A2,MARCH2!$A$2:$A$333,0),)<>A2,1)

And

In MARCH2 sheet

=IFERROR(INDEX(MARCH!A$2:A$343,MATCH($A2,MARCH!$A$2:$A$343,0),)<>A2,1)


Markmzz
 
Upvote 0
MariosB,

Thanks for the feedback.

You are very welcome. Glad I could help.


If I change my ID column to C (i leave A and B for personal usage) what do I have to change in the code?

1. So, we care inserting two blank columns into BOTH worksheets?
 
Last edited:
Upvote 0
MariosB,

NEW sample raw data worksheets:


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



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


After the NEW macro in both worksheets:


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 CompareW2toW1_V2()
' hiker95, 02/24/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
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 CompareW2toW1_V2 macro.
 
Upvote 0
Yes hiker95 I meant that I have two blank columns in both workseets. And I tested your new module and guess what... it worked:D Thank you so much for all your help, really appreciate it!!
 
Upvote 0
Hi Markmzz and thank you for your help as well. I am interested in your solution with the formulas too but can you be a bit more specific? Sorry but I'm not an advanced user or Excel:) First of all I'm not exactly sure what cells to select to insert the conditional formatting. Is is just one cell, a range or the whole set of data? Also when I tried to use your formula I got an error saying that I can't use reference across different worksheets
 
Upvote 0
MariosB,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0
Hi Markmzz and thank you for your help as well. I am interested in your solution with the formulas too but can you be a bit more specific? Sorry but I'm not an advanced user or Excel:) First of all I'm not exactly sure what cells to select to insert the conditional formatting. Is is just one cell, a range or the whole set of data? Also when I tried to use your formula I got an error saying that I can't use reference across different worksheets

Hi MariosB,

I'm sorry, but this formula only work with Excel 2010 or 2013.

You can't use conditional formatting between two worksheets in the same workbook in Excel 2007 (without names).

Markmzz
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

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