How to Compare in Excel? (10 Practical Examples)

In the following overview image, we have compared two different lists containing the available products in a store and ordered products. If the ordered products are in the list of available products, they are remarked as “Available” and if they are not in the list, they are remarked as “Not Available”.

Overview to Compare in Excel


Compare Two Columns Row-by-Row
   ⏵Compare Numeric Values
   ⏵Compare Text Strings (Case Sensitive/Insensitive)
   ⏵Comparing Date Values in Excel
Compare Multiple Columns for Row Matches
Compare Two Lists for Similarities and Differences
Compare Two Lists and Pulling Matched Data
Compare and Highlight Row Similarities and Differences
Compare Any 2 Cells and Write Remarks in Excel
Comparing 2 Columns in Different Sheets
Comparing 2 Different Excel Workbooks
Statistical Comparison in Excel
Using VBA to compare 2 Columns Based on User Input


Method 1 – Compare Two Columns Row-by-Row in Excel

Case 1.1 – Compare Numeric Values

In the following dataset, we have a list of 10 electronic products along with their current and previous prices listed accordingly. Now we will compare these prices and evaluate whether the prices have changed or not.

Sample Data for Comparing Numeric Values

Steps:

  • Inside cell E7 copy the following formula:
=IF(C7=D7,"No Change","Change")
  • Press Enter. This will return “Change” if the prices are not the same or return “No Change” if the prices remain constant.

Entering Formula to Compare Numeric Values

  • Use the Fill Handle to copy the formula in the other cells below.

The rows with “No Change” remarks have been highlighted in the sample for better visualization.

Autofill Formula for Numeric Comparison


Case 1.2 – Compare Text Strings (Case Sensitive/Insensitive)

In the dataset below, we have taken a list of famous brands and the names of their owners. All the brand names are given after their owners’ names. We will compare these text strings and evaluate if the strings are matched or not.

Sample Data for Comparing Text String (Insensitive)

Steps:

  • Copy the following formula inside cell D7 for a case-insensitive match:
=IF(B7=C7,"Match","No Match")
  • Press Enter and use AutoFill to copy the formula down.

Only the misspellings will result in “No Match”. Otherwise, all the names are matched regardless of their case sensitivity.

Formula to Compare Text Strings (Insensitive)

  • To compare case-sensitive text strings, use the formula:
=IF(EXACT(B7,C7),"Match","No Match")

Only the exact matches with the right spellings and case sensitivities are matched.

Formula to Compare Text Strings (Sensitive)


Case 1.3 – Comparing Date Values in Excel

In the following dataset, we have a list of 10 projects along with their due dates and submission dates. Let’s compare these dates and evaluate if the projects were submitted before the deadlines or not.

Sample Dataset to Compare Dates

Steps:

  • Put the following formula inside cell E7:
=IF(C7>D7,"Delayed","On Time")
  • Press Enter and use the Fill Handle to copy the formula into the rest of the cells.

The projects that were submitted before the deadline are remarked with “On Time”. And the projects that were submitted past the due date are remarked with “Delayed”.

Formula for Comparing Dates


Method 2 – Compare Multiple Columns for Row Matches

In the following dataset, we have a list of 10 electronic products along with their prices in the years 2021, 2022, and 2023. Let’s compare these 3 columns in Excel and evaluate whether these prices are fully stable, almost stable, or unstable.

Sample Data for Comparing Multiple Columns

Steps:

  • Input the following formula inside cell F7:
=IFS(AND(C7<>D7,D7<>E7,C7<>E7),"Unstable",AND(C7=D7,D7=E7,C7=E7),"Fully Stable",OR(C16=D16,D16=E16,C16=E16),"Almost Stable")
  • Press Enter and use Autofill to copy the formula down.

The prices that are different in all 3 years are remarked as “Unstable”.

The prices that are constant throughout any two years and different in only one year are remarked as “Almost Stable”.

Finally, the prices that have remained constant for all three years are remarked as “Fully Stable”.

Formula to Compare Multiple Columns


Method 3 – Compare Two Lists for Similarities and Differences in Excel

In the dataset below, we have two separate lists. One contains the ordered products, and the other contains the products that are currently available in the store. Let’s compare these lists and determine which ordered products are currently available in the store.

Sample Data for Comparing 2 Lists

Steps:

  • Inside cell E7, copy the following formula:
=IF(COUNTIF($B:$B, $D7)=0, "Not Available", "Available")
  • Press Enter and use the Fill Handle to copy the formula in the other cells below.

The available products are highlighted for better visualization.

Formula to Compare 2 Lists

Now, if any new item is listed as available in the store (by putting a new row and entering the value) and matches the list of ordered products, it will be automatically marked as “Available” as well as highlighted.

Adding New Items to One List Changes Remarks


Method 4 – Compare Two Lists and Pulling Matched Data

We have a list of 10 electronic products along with their prices in the following dataset. In cell E7, we will make a drop-down list in Excel with some product names that are not all available in the Electronic Product list. Now, we will select any of the products from the search product list to compare their value with the electronic product lists. For any matched value in the following lists, it will pull the price data of the electronic product, and for any unmatched value, it will return “Not Available”.

Sample Data for Comparing 2 Lists and Pulling Matched Data

Steps:

  • Inside cell F7, copy the following formula:
=IFERROR(VLOOKUP(E7,B7:C16,2,FALSE),"Not Available")
  • Press Enter.

Formula to Compare 2 Lists and Pulling Matched Data

The following GIF shows the corresponding prices getting changed as we select different products. If we select a product that is not included in the given list, it will show “Not Available”.

Selecting Data from Drop-Down List

Note: We can alternatively use any of the following two formulas:

=XLOOKUP(E7,B7:B16,C7:C16,,0)

Or,

=INDEX(B7:C16,MATCH(E7,B7:B16,0),2)

Method 5 – Compare and Highlight Row Similarities and Differences

In the dataset below, we have a column containing the previous price and another column containing the current prices of 10 electronic items. Let’s compare these columns and highlight the rows containing the products with changed prices.

Sample Dataset for applying Conditional Formatting

Steps:

  • Select the range B7:D16.
  • Go to Home, select Conditional Formatting in the Styles group, and choose New Rule…

Selecting New Rule for Conditional Formatting

  • A dialogue box named New Formatting Rule pops out.
  • Under Select a Rule Type:, select Use a formula to determine which cells to format.
  • Under Format values where this formula is true:, copy the following formula:
=$C7<>$D7
  • Click on Format…

Inputting Conditional Formatting Formula

  • A new dialogue box named Format Cells pops out.
  • Click on the Fill tab and select any suitable fill color.
  • Click on OK.

Selecting Suitable Fill Color

  • Click on OK inside the New Formatting Rule dialogue box.

Finalizing Conditional Formatting

  • This highlights the rows containing the products with the changed prices.

Condional Formatting Result


Method 6 – Compare Any 2 Cells and Write Remarks in Excel

In the following dataset, we have a list of 10 electronic products along with their monthly sales. The cell C18 holds the value of the maximum sales.

The formula for calculating the maximum sales is:

=MAX(C7:C16)

Now we will compare the maximum sales in C18 with the sales of the selected product from the drop-down list in cell C19 and get the correct remark.

Sample Data for Comparing Any Two Cells

 Steps:

  • Copy the following formula inside cell C20:
=IF(VLOOKUP(C19,B7:C16,2,FALSE)=C18,"Yes", "No")
  • Press Enter.

Formula to Compare Any 2 Cells and Writing Remarks

  • The following GIF shows that the remark changes by comparing two cells as we select different products.

Selecting Data from Drop-Down List to Compare 2 Cells


Method 7 – Compare 2 Columns in Different Excel Worksheets

In the dataset below, we have the previous prices of 10 electronic products in one worksheet and the current prices of the same products in another worksheet. Let’s determine whether the prices have changed or not.

Sample Data for Comparing 2 Columns in Different Sheets

Steps:

  • Go to the ComparingSheets_2 sheet.
  • Select cell D7.
  • Input the following formula:
=IF(C7=ComparingSheets_1!C7,"No","YES")
  • Press Enter and use the Fill Handle to copy the formula into the rest of the cells.

The current prices that are different from the previous prices are remarked with “Yes” and the current prices that are similar to the previous prices are remarked with “No”.

Formula for Comparing 2 Columns in 2 Different Sheets


Method 8 – Compare 2 Different Workbooks in Excel

In the dataset below, we have the previous prices of 10 electronic products in one workbook and the current prices of the same products in another workbook.

Workbook Containing Previous Prices to Compare Workbooks in Excel

Steps:

  • Go to the Compare in Excel Sub1 workbook and the Comparing Workbooks_2 worksheet.
  • Select cell D7 and insert the following formula:
=IF(C7='C:\Users\Gadget 360\Desktop\[Compare in Excel.xlsm]ComparingWorkbooks_1'!C7,"No","YES")
  • Press Enter and use the Fill Handle to copy the formula into the rest of the cells.

The current prices that are different from the previous prices are remarked with “Yes” and the current prices that are similar to the previous prices are remarked with “No”.

Workbook Containing Current Prices to Comapre Workbooks in Excel

Note: In the formula inside the IF function, we have used the folder path appropriate for us. However, the users should use their own folder path where the files are actually located. For best results, we recommend putting the files in the same folder, which allows you to omit the folder path and just input the file name and extension.


Method 9 – Statistical Comparison in Excel

In the following dataset, we have six monthly sales quantities of wireless and wired headphones in two different columns. We will calculate the Mean, Standard Deviation, Coefficient of Variation, and Range of these two different lists.

To calculate the Mean of Wired Headphones use the formula below:

=AVERAGE(C7:C12)

The formula to calculate the Standard Deviation of Wired Headphones is:

=STDEV.S(C7:C12)

To calculate the Coefficient of Variation of Wired Headphones use the formula below:

=C16/C15

To calculate the Range of Wired Headphones use the formula below:

=MAX(C7:C12)-MIN(C7:C12)

We have also calculated the Mean, Standard Deviation, Coefficient of Variation, and Range for the Wireless Headphones.

Sample Dataset for Statistical Comparison

Steps:

  • Put the following formula inside cell C19:
=IF(C15>D15, "Wired Headphones", "Wireless Headphones")

Formula to Compare Statistical Parameters


Method 10 – Comparing 2 Columns Based on User Input Using Excel VBA

Let’s make a form where the users will enter the column names to compare and then input the column name where they want to get the output.

Steps:

  • Click on Developer and select Visual Basic.

Opening Visual Basic Window

  • A new window named Microsoft Visual Basic for Applications will open.
  • Inside the Visual Basic window, click on Insert and select Module.
  • A blank module will open for you to write the VBA code.

Inserting Module to Write Code

  • Inside the module, copy the following code:

VBA Code for Comparing in Excel

Code Syntax:

Sub CompareColumnsWithUserInput()
Dim sheet As Worksheet
Dim rowEnd As Long
Dim i As Long
Dim comparecolumn1 As String
Dim comparecolumn2 As String
Dim outputcolumn As String

' Set the worksheet
Set sheet = ThisWorkbook.Sheets("Comparing Using VBA")

' Get user input for columns to compare
comparecolumn1 = InputBox("Enter the name of the first column to compare (e.g., A):")
comparecolumn2 = InputBox("Enter the name of the second column to compare (e.g., B):")

' Get user input for result column
outputcolumn = InputBox("Enter the name of the column to output the result (e.g., C):")

' Find the last row in the specified columns
rowEnd = sheet.Cells(sheet.Rows.Count, comparecolumn1).End(xlUp).Row

' Loop through each row and compare values
For i = 7 To rowEnd ' Assuming data starts from row 7, modify as needed
If sheet.Cells(i, comparecolumn1).Value = sheet.Cells(i, comparecolumn2).Value Then
sheet.Cells(i, outputcolumn).Value = "Not Changed"
Else
sheet.Cells(i, outputcolumn).Value = "Changed"
End If
Next i
MsgBox ("The changed prices are detected!")
End Sub

  • Save the file and close the Visual Basic window.
  • Click on Developer and select Macros.
  • Inside the dialogue box named Macro, select the code you have just written and click on Run.
  • Three dialogue boxes will appear one by one. In the first two dialog boxes, we will input the two column names to compare. In the last dialog box, we’ll input the column name where we want to get the output.

This will remark the changed prices as “Changed” and the unchanged prices as “Not Changed”. Changed prices are highlighted for better visualization.

Comparing 2 Columns Using VBA


Download Practice Book


Compare in Excel: Knowledge Hub


<< Go Back to Learn Excel

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Md. Nafis Soumik
Md. Nafis Soumik

Md. Nafis Soumik graduated from Bangladesh University of Engineering & Technology, Dhaka, with a BSc.Engg in Naval Architecture & Marine Engineering. In January 2023, he joined Softeko as an Excel and VBA content developer, contributing 50+ articles on topics including Data Analysis, Visualization, Pivot Tables, Power Query, and VBA. Soumik participated in 2 specialized training programs on VBA and Chart & Dashboard designing in Excel. During leisure, he enjoys music, travel, and science documentaries, reflecting a diverse range... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo