# How Can I Compare Data in Two Excel Spreadsheets

**Spreadsheet**– This article describes two methods that you can use to compare data from two columns of the Microsoft Excel spreadsheet and to look for duplicate entries.

### More information

### Method 1: Use a Worksheet Formula

To use a worksheet formula to compare the data in two columns, follow these steps:

- Start Excel.
- On a new worksheet, type the following data (leave column B empty):
A1: 1 B1: C1: 3 A2: 2 B2: C2: 5 A3: 3 B3: C3: 8 A4: 4 B4: C4: 2 A5: 5 B5: C5: 0

- In cell B1, type the following formula:
= IF (ISERROR (MATCH (A1, $ C $ 1: $ C 5.0)), “”, A1)
- Select cells B1: B5.
- In Microsoft Office Excel 2003 and in earlier versions of Excel, point to Fill on the Edit menu , and then click Down .In Microsoft Office Excel 2007 and Excel 2010, click
**Fill**in the**Modify**group , and then click**Down**.Duplicate numbers are shown in column B, as in the following example:A1: 1 B1: C1: 3 A2: 2 B2: 2 C2: 5 A3: 3 B3: 3 C3: 8 A4: 4 B4: C4: 2 A5: 5 B5: 5 C5: 0

### Method 2: Use a Visual Basic Macro

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to the implied warranty of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is displayed and the tools used to create and debug procedures. Microsoft technical support engineers can explain the functionality of a particular procedure. However, they will not modify these examples to provide greater functionality or create procedures that meet your specific requirements. To use a Visual Basic macro to compare data from two columns, follow the steps in the following example:

- Start Excel.
- Press ALT + F11 to start the Visual Basic Editor.
- On the Insert menu , click Module .
- Type the following code in a module sheet:
`Sub Find_Matches() Dim CompareRange As Variant, x As Variant, y As Variant ' Set CompareRange equal to the range to which you will ' compare the selection. Set CompareRange = Range("C1:C5") ' NOTE: If the compare range is located on another workbook ' or worksheet, use the following syntax. ' Set CompareRange = Workbooks("Book2"). _ ' Worksheets("Sheet2").Range("C1:C5") ' ' Loop through each cell in the selection and compare it to ' each cell in CompareRange. For Each x In Selection For Each y In CompareRange If x = y Then x.Offset(0, 1) = x Next y Next x End Sub`

- Press ALT + F11 to return to Excel.
- Enter the following data (leave column B empty):
A1: 1 B1: C1: 3 A2: 2 B2: C2: 5 A3: 3 B3: C3: 8 A4: 4 B4: C4: 2 A5: 5 B5: C5: 0

- Select the range a1: a5.
- In Excel 2003 and in earlier versions of Excel, point to Macro on the Tools menu , and then click Macros .In Excel 2007 and Excel 2010, click the
**Developer**tab , and then click**Macro**in the**Code**group . - Click Find matches, and then click Run .

Duplicate numbers are shown in column B. Matching numbers will be placed next to the first column, as shown here:

A1: 1 B1: C1: 3 A2: 2 B2: 2 C2: 5 A3: 3 B3: 3 C3: 8 A4: 4 B4: C4: 2 A5: 5 B5: 5 C5: 0