ow to compare data in Excel 2010

Dawud Beale

New Member
Joined
Sep 11, 2013
Messages
2
Hi everyone.
I have some data I need to compare in Excel 2010.
It looks something like this:
1 2 1 2 1 2
1 2 1 5 1 2
1 2 1 2 1 2
1 8 1 2 9 2
1 2 1 2 1 2
1 2 4 2 1 2
1 2 1 2 1 2
and it needs to be compared with:
1 2
1 2
1 2
1 2
1 2
1 2
1 2
These same two columns should be used to compare all 6 columns in the first piece of data. The 1 columns should be compared and the 2 columns should be compared.
As an output I need a list of all cells that don't match what they are being compared with.
Any suggestions on how I might achieve this?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Dawud Beale,

We do not know what cells, rows, columns, your two tables are in.

Sample raw data:


Excel 2007
ABCDEFGHIJK
112121212
212151212
312121212
418129212
512121212
612421212
712121212
8
Sheet1


After the macro:


Excel 2007
ABCDEFGHIJK
112121212A1:B1,C1:D1,E1:F1
212151212A2:B2,E2:F2
312121212A3:B3,C3:D3,E3:F3
418129212C4:D4
512121212A5:B5,C5:D5,E5:F5
612421212A6:B6,E6:F6
712121212A7:B7,C7:D7,E7:F7
8
Sheet1


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).

Where to put the macro code:
1. Open a copy of your workbook in which to store the macro code.
2. Open the Visual Basic Editor (Alt+F11).
3. Insert a standard module (Insert, Module).
4. Copy the macro code, and, paste the macro code into the module on the right where the cursor is flashing.
5. Return to Excel (Alt+Q).
6. Save your copy of the workbook.

How to use the macro code:
1. Display the Macro dialog box (Alt+F8).
2. Click and/or select the macro.
3. Click and/or select "Run".

Code:
Option Explicit
Sub CompareData()
' hiker95, 09/11/2013
' http://www.mrexcel.com/forum/excel-questions/725858-ow-compare-data-excel-2010-a.html
Dim a As Variant, o As Variant
Dim i As Long, c As Long, h As String
Columns("K:K").ClearContents
a = Cells(1, 1).CurrentRegion
o = Cells(1, 9).CurrentRegion.Resize(, 3)
For i = 1 To UBound(o, 1)
  h = ""
  For c = 1 To UBound(a, 2) Step 2
    If o(i, 1) = a(i, c) And o(i, 2) = a(i, c + 1) Then
      h = h & Range(Cells(i, c), Cells(i, c + 1)).Address & ","
    End If
  Next c
  If Right(h, 1) = "," Then h = Left(h, Len(h) - 1)
  o(i, 3) = Replace(h, "$", "")
Next i
Cells(1, 9).Resize(UBound(o, 1), UBound(o, 2)) = o
Columns("K:K").AutoFit
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 CompareData macro.
 
Upvote 0

Forum statistics

Threads
1,215,516
Messages
6,125,285
Members
449,218
Latest member
Excel Master

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