How to Return YES If 2 Cells Match in Excel (10 Methods)

Below is a dataset that contains the names of the school’s tennis and rugby players. Some of them play both games.


Method 1 – Use the Excel IF Function to Return YES If 2 Cells Match

 

1.1 IF Function with Matching Condition

Steps:

  • Go to Cell D5.
  • Enter the following formula:
=IF(B5=C5,"Yes","")

Use Excel IF Function to Return YES If 2 Cells Match

  • Press the Enter button and drag the Fill Handle icon.

Use Excel IF Function to Return YES If 2 Cells Match

When the cells of both columns match, the status is Yes. The columns in the red rectangles are not the same, so they show blank returns.


1.2 IF Function with Odd Data

Steps:

  • Go to Cell D5 and replace the previous formula with the one below:
=IF(B5:B9<>C5:C9,"","Yes")

Use Excel IF Function to Return YES If 2 Cells Match

  • Press Enter.

We used the range in the formula. So, no need to drag the formula.


Method 2 – Insert the Excel EXACT Function to Match 2 Cells and Return YES

Steps:

  • Go to Cell D5.
  • Enter the following formula:
=IF(EXACT(B5,C5),"Yes","")

Insert Excel EXACT Function to Match 2 Cells and Return YES

  • Press Enter and pull the Fill Handle icon.


Method 3 – Use AND and IF Functions to Show YES If 2 Cells Are the Same

Steps:

  • Enter the following formula in Cell D5:
=IF(AND(B5=C5),"Yes","")

Use AND and IF Functions to Show YES If 2 Cells Are the Same

 

  • Press the Enter button and pull the Fill Handle icon.


Method 4 – Combine the COUNTIF and IF Functions to Test 2 Cells

Steps:

  • Go to Cell D5.
  • Enter the following formula:
=IF(COUNTIF(B5,C5),"Yes","")

Combine COUNTIF and IF Functions to Test 2 Cells

  • Press the Enter button and drag the Fill Handle icon.


Method 5 – Test 2 Cells Using Excel OR Function and Show YES

Steps:

  • Go to Cell D5.
  • Enter the formula below:
=IF(OR(B5=C5),"Yes","")

Test 2 Cells Using Excel OR Function and Show YES

  • Press Enter button and pull the Fill Handle icon.


Method 6 – Combination of MATCH and ISERROR Functions to Test Two Cells and Return YES

Steps:

  • Enter the following formula on Cell D5:
=IF(ISERROR(MATCH(B5,C5,0)),"","Yes")

Combination of MATCH and ISERROR Functions to Test Two Cells and Return YES

  • Press the Enter button and drag the Fill Handle icon.


Method 7 – Join IF and SUM Functions to Test 2 Cells in Excel

Steps:

  • Go to Cell D5.
  • Enter the following formula:
=IF(SUM(--(B5=C5))=1, " Yes", "")

Join IF and SUM Functions to Test 2 Cells in Excel

  • Press the Enter button and drag the Fill Handle icon.


Method 8 – Combine IF, ISERROR, and VLOOKUP Functions to Test 2 Cells and Print YES

Steps:

  • Enter the following formula in Cell D5:
=IF(ISERROR(VLOOKUP(C5, B5, 1, FALSE)),"","Yes")

Combine IF, ISERROR, and VLOOKUP Functions to Test 2 Cells and Print YES

  • Press the Enter button and pull the Fill Handle icon.


Method 9 – Join IF and TRIM Functions to Test 2 Cells

Steps:

  • Go to Cell D5.
  • Enter the following formula:
=IF((TRIM(B5)=TRIM(C5)),"Yes","")

IF and TRIM Functions to Test 2 Cells

  • Press Enter and drag the Fill Handle icon.


Method 10 – Excel VBA to Test 2 Cells and Print Yes When They Match

Steps:

  • Go to the Developer tab.
  • Click on the Record Macro option.
  • Set a name for the Macro and click OK.

Excel VBA to Test 2 Cells and Print Yes When They Match

  • Set a name for the Macro and click OK.
  • Click on Macros from the Ribbon and Step Into it.

Excel VBA to Test 2 Cells and Print Yes When They Match

  • Enter the following VBA code:
Sub Match_2_Cells()
Dim n, m As Range
Set n = Application.InputBox(prompt:="Sample_1", Type:=8)
Set m = Application.InputBox(prompt:="Sample_2", Type:=8)
If n.Value = m.Value Then
Range("E6").Value = "Yes"
Else
Range("E6").Value = "No"
End If
End Sub

Excel VBA to Test 2 Cells and Print Yes When They Match

  • Press F5 to run the code.
  • A dialog box will appear. Enter the 1st cell reference.

Excel VBA to Test 2 Cells and Print Yes When They Match

  • Press OK, put a cells cell reference in the 2nd dialog box.

You’ll get the below result.

Excel VBA to Test 2 Cells and Print Yes When They Match

 


Apply Conditional Formatting to Highlight When 2 Cells Match

Steps:

  • Go to the Home tab.
  • Choose Highlight Cells Rules from the Conditional Formatting.
  • Select Duplicate Values from the list.

Apply Conditional Formatting to Highlight When 2 Cells Match

  • A new dialog box will appear. Choose Duplicate and click OK.

Apply Conditional Formatting to Highlight When 2 Cells Match

When 2 cells match, the color of the cells changes.


Download the Practice Workbook


<< Go Back To Excel Compare Cells | Compare in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Alok Paul
Alok Paul

Alok Paul has completed his B.Sc. in Electronics and Telecommunication Engineering from East West University. He has been working on the ExcelDemy project for more than 2 years. He has written 220+ articles and replied to numerous comments. He is experienced in Microsoft Office, especially in Excel. He also led some teams on Excel and VBA content development. He has a keen interest in Advanced Excel, Data analysis, Excel Pivot Table, Charts, and Dashboard. He loves to research... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo