How Can You Compare Tables in Excel? (All You Need to Know)

The following sample dataset will be used for illustration.

0- an overview image of comparing tables in Excel


Apply Conditional Formatting to Compare Tables and Highlight Differences
 ⏵ Use Unique Feature to Compare Two Tables
 ⏵ Use Formula to Compare Two Tables
Apply VBA to Compare Two Tables and Highlight Differences
Apply Power Query to Compare Two Tables and Merge All Values
View Two Tables Side by Side in Excel to Compare Them
Steps to Compare Two Pivot Tables
 ⏵ Create Two Pivot Tables in One Sheet
 ⏵ Insert the Formula to Calculate Differences Between Pivot Tables
Frequently Asked Questions
Compare Tables in Excel: Knowledge Hub


Method 1 – Apply Conditional Formatting to Compare Tables and Highlight Differences in Excel

You can apply the built-in unique feature or a custom formula to compare tables and highlight the differences. In the custom formula, you can use the Not Equal (“<>“) operator or the COUNTIF function.


1.1 Using Unique Feature to Compare Two Tables

  • Select full table cell range B4:F10.
  • Go to the Home tab >> Conditional Formatting >> Select New Rule.

6-selecting new rule to utilize unique formatting rule

  • Select “Format only unique or duplicate values” from the Rule Type section under the New Formatting Rule dialog box.
  • Select “unique” from the Format all section.
  • Choose a background color using the Format button and click OK.

7- choosing “format only unique or duplicate values” and background color

The differences between the two tables are highlighted.

8- comparing two tables and highlighting differences by utilizing unique formatting rule


1.2 Using Formula to Compare Two Tables

We can use the Not Equal (“<>”) operator or the COUNTIF function in the Conditional Formatting formula to compare two tables.


Using Not Equal (“<>”) Operator

  • Select cells F5:F10.
  • Go to the Home tab >> Conditional Formatting >> Select New Rule.

1- selecting a new rule to use the not equal operator in Excel to compare two tables

  • Select “Use a formula to determine which cells to format” under the Select a Rule Type section from the New Formatting Rule dialog box.
  • Enter the following formula in the Edit the Rule Description box and click on Format.
=F5<>C5

2- Editing New Formatting Rule dialog box

  • Select a color from the Background Color section under the Fill tab.
  • Click OK.

3- selecting background color under Fill tab

  • Click on OK.

4- setting conditional formatting to compare two tables

The differences are highlighted as shown below.

5- final output image of using not equal operator in excel to compare two tables


Using COUNTIF Function

The COUNTIF function counts the number of cells within a range that meet the given condition. The syntax of this function is given below:

=COUNTIF(range, criteria)
8.5- syntax of COUNTIF function

Click the image for a detailed view

  • Select cell range C5:C10.
  • Go to Home tab >> Conditional Formatting >> Select New Rule.

9- selecting a new rule to implement the COUNTIF function to compare two tables

  • Select “Use a formula to determine which cells to format” from the Select a Rule Type section under the New Formatting Rule dialog box.
  • Enter the following formula in the Edit the Rule Description box.
=COUNTIF(F5:F10,C5)=0
  • We are checking if our value from the C column is in the F We’ll get 0 if it’s not there.
  • We will format the cells that are not in the F5:F10 range.
  • Choose a background color from the Format section and click OK.

10- choosing “Use a formula to determine which cells to format” and background color

The two tables will be compared and the differences will be highlighted as shown below.

11- final output image of implementing COUNTIF function to compare two tables


Method 2 – Apply VBA to Compare Two Tables and Highlight Differences

  • From the Developer tab >> select Visual Basic.

12- selecting visual basic to compare two tables

  • Select Module from the Insert tab.

13- selecting module from insert section

  • Insert the following code in that module.
Sub HighlightDifference()
Dim i As Long
    For i = 1 To Cells(Rows.Count, "C").End(xlUp).Row
        If Cells(i, "C") <> Cells(i, "F") Then
            Cells(i, "F").Interior.Color = vbYellow
        End If
    Next i
End Sub

14- VBA code to compare two tables and highlight differences

Code Breakdown:

  • Dim i As Long → Declares a variable i to use as a loop counter.
  • For i = 1 To Cells(Rows.Count, “C”).End(xlUp).Row

       If Cells(i, “C”) <> Cells(i, “F”) Then

            Cells(i, “F”).Interior.Color = vbYellow

      End If

This Loop goes through rows in column C, starting from row 1 and going up to the last non-empty row. It checks if the value in the current row of column C is different from the value in the same row of column F. If values are different, it changes the background color of the cell in column F to yellow.

  • Next i → Refers to move to the next iteration of the loop.

  • Press F5 to run the code.
  • The differences will be highlighted in the second table.

15- final output image after running the VBA code to compare and highlight differences between two tables


Method 3 – Apply Power Query to Compare Two Tables and Merge All Values

We have modified the dataset to illustrate this method. We have added a new column named Item ID to add more data to the dataset. We will convert all our dataset ranges into tables.

  • Click on any cell of the Products Record range >> go to Insert tab >> Select Table.

16- converting dataset into tables

  • From the Create Table window choose the range as B4:D13 >> tick on the option My table has headers >> click OK.

17- editing create table window

  • The Products Record dataset will be converted into a table.

18- created table from products record dataset

  • To name this table, click on any value inside the table >> go to the Table Design tab >> Properties >> enter Products in the Table Name text box.

19- naming the create table

  • Similarly, create two more tables named Shop_A and Shop_B from the individual Shop A and Shop B product records.

20- creating Shop A and Shop B tables

  • Right-click on any cell inside the Products Record table and choose the Get Data from Table/Range option from the context menu.

21- selecting Get Data from Table/Range option from the context menu

  • You can see that the Products table is shown in the Power Query.

22- showing products table in power query

  • In the Home tab of the Power Query, click on the arrow inside the Close & Load button >> choose the option Close & Load To.

23- selecting Close & Load To option from power query home tab

  • Select the radio button on the option Only Create Connection and click OK from the Import Data box.

24- editing import data window

  • Repeat the procedures individually for the Shop_A and Shop_B tables to import data from the given tables to Power Query.

25- importing data from Shop_A and Shop_B tables to Power Query

  • Right-click on the Queries pane area >> choose the New Query option >> Other Sources option >> Select Blank Query.

26- editing queries pane area

  • A new query will be created.
  • Rename it as “Merge All Values”.

27- creating new query named Merge All Values

  • Click on the Merge All Values query and enter the following formula to compare two tables and merge values through the power query.
  • Press Enter.
=List.Union({Shop_A[Name],Shop_B[Name]},Comparer.OrdinalIgnoreCase)

28- inserting query formula to compare two tables and merge values

We have compared and merged two tables and got all the unique items from Shop A and Shop B.


Method 4 – View Two Tables Side by Side in Excel to Compare Them

We can arrange two Excel windows side by side using “View Side by Side” mode. Using this method, we can visually compare two workbooks or two sheets in a single workbook.

  • Open both Excel files you want to compare.
  • Go to the View tab>> Window group>> Arrange All.
  • Select Vertical from Arrange Windows and click OK.

29- using "View Side by Side" mode to compare two tables from two different workbooks

  • The two Excel windows will appear side-by-side as shown in the following image.
30- final output image of  using View Side by Side mode to compare two tables from two different workbooks

Click the image for a detailed view


Method 5 – How Can You Compare Two Pivot Tables in Excel

Step 1 – Creating Two Pivot Tables in One Sheet

We will create two pivot tables in one sheet using the two datasets for Shop A and Shop B.

  • Go to the Insert tab >> PivotTable drop-down >> Select From Table/Range.

31- creating a pivot table from the dataset for Shop A

  • Select the range of the first table for Shop A in the Table/Range text box from the PivotTable from table or range dialog box.
  • Select New Worksheet and click OK.
32- selecting range to create a pivot table for a dataset of Shop A

Click the image for a detailed view

  • You’ll get a new sheet where you will have two portions; PivotTable1 and PivotTable Fields.

33- taken to a new worksheet to create pivot table for shop A

  • Drag down Item to Rows area and Price to the Values.

34- arranging rows and values area

  • To insert the second table in this same sheet, we have to insert the table again.
  • Select cell A14 or any other cell where you want to enter the second PivotTable.
  • Go to the Insert tab >> PivotTable dropdown >> Select From Table/Range.

35- creating pivot table from dataset for Shop B

  • Select the range of the second table for Shop B in the Table/Range text box in the PivotTable from table or range dialog box.
  • The Existing Worksheet option and the Location value will be selected automatically.
  • Click OK.
36- selecting range to create pivot table for dataset of Shop B

Click the image for a detailed view

  • Drag down Item to the Rows area and Price to the Values.

Dragging the Pivot Table Fields

  • We have inserted two pivot tables in one sheet.
  • We created a space for gathering the differences between different items following the second table.

Table for Calculating Difference Between Items of Two Tables


Step 2 – Inserting the Formula to Calculate Differences Between Pivot Tables

  • Enter the following formula in cell B26.
=GETPIVOTDATA("Sum of Price",$A$4,"Item",D8)-GETPIVOTDATA("Sum of Price",$A$15,"Item",D8)
  • Use the Fill Handle for the remaining cells.
  • You will get the values for the rest of the cells and will be able to calculate all of the differences between the item prices for Shop A and Shop B.

 

Applying GETPIVOTDATA function to compare tables in Excel


Download Practice Workbook


Compare Tables in Excel: Knowledge Hub


<< Go Back to Compare | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Nujat Tasnim
Nujat Tasnim

Nujat Tasnim, BSc in Computer Science and Engineering from American International University-Bangladesh, has a year-long tenure with ExcelDemy. Initially a Content Developer at SOFTEKO, she transitioned to the Software Team as Junior Software Quality Assurance Engineer. Currently serving as a Junior SQA Engineer at SOFTEKO, she excels in SDLC, STLC, and requirement analysis and possesses profound insights into OOP-related software development processes. Nujat is also proficient in design software like Photoshop and Illustrator, contributing diverse skills to her... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo