# How to Compare Two Strings for Similarity in Excel (6 Methods)

In this tutorial, I am going to show you 6 easy methods on how to compare two strings for similarity in Excel. You can use these methods even in large datasets to find out cells that have exactly or partially similar strings. Throughout this tutorial, you will also learn some important Excel tools and techniques that will be very useful in any Excel-related task.

## How to Compare Two Strings for Similarity in Excel: 6 Methods

We have taken a concise dataset to explain the steps clearly. The dataset has approximately 7 rows and 2 columns. Initially, we are keeping all the cells in General format. For all the datasets, we have 2 unique columns which are Sales Person Full Name and First Name. Although we may vary the number of columns later on if that is needed.

### 1. Using Highlight Cells Rules Feature

In this first method, we will see how to compare two strings for similarity using the Highlight Cells Rules in Excel. Follow the steps below.

Steps:

• First, select all the cells from B5 to C10.

• Next, go to the Home tab and click on Conditional Formatting.
• Here, go to Highlight Cells Rules and click on Duplicate Values.

• Now, simply click on OK.

• As a result, this should highlight the values that are similar.

### 2. Applying New Rule Feature

We can also use the New Rule feature in Excel which gives us custom options to compare two strings for similarity. Let us see how to do that.

Steps:

• To begin with, again select the cells from B5 to C10.

• Now, navigate to Conditional Formatting under the Home tab and click on New Rule.

• Next, in the new window, select Format only unique or duplicate values and click on Format.

• Then, select a color under the Fill tab and click OK in this window and also in the next window.

• Consequently, this will highlight the values that are similar in the dataset.

### 3. Utilizing Equal Operator

The equal operator in Excel can evaluate whether a statement is TRUE or FALSE. We will use this symbol to quickly compare two strings for similarity. Below are the detailed steps.

Steps:

• First, go to cell D5 and insert the following formula:
`=B5=C5`

• Now, press Enter and copy this formula to the other cells using Fill Handle.
• Finally, this will give TRUE or FALSE values based on whether the values match or not.

### 4. Comparing Using EXACT Function

The EXACT function in Excel is very useful if we want to compare two text strings for similarity. For this, we just need to give the two strings as inputs to this function. Let us see the step-by-step process.

Steps:

• To begin this method, double-click on cell D5 and insert the formula below:
`=EXACT(B5,C5)`

• Next, press the Enter key and consequently, this will insert TRUE if the values are exactly similar.

### 5. Using SEARCH Function

The SEARCH function in Excel can find the position of one string inside another string. So, we should be able to use this function to compare two strings for similarity. Follow the steps below to do this.

Steps:

• To start this method, navigate to cell D5 and type in the following formula:
`=IFERROR(IF(SEARCH(C5,B5),"Similar"),"Not Similar")`

• After that, press the Enter key or click on any blank cell.
• Immediately, this will give you the result as similar or not for all the data.

🔎 How Does the Formula Work?

• SEARCH(C5,B5): This portion gives the true value as 1.
• IF(SEARCH(C5,B5),”Similar”): This part gives the result back as Similar.
• IFERROR(IF(SEARCH(C5,B5),”Similar”),”Not Similar”): This also returns the final value as Similar.

### 6. Applying VBA Code

If you are familiar with VBA in Excel, you can easily compare two strings for similarity. Although we will write a little lengthy code, you can just copy this code into your own file. Let us see how to write VBA code for this.

Steps:

• For this method, go to the Developer tab and select Visual Basic.

• Now, select Insert in the VBA window and click on Module.

• Next, type in the formula below in the new window:
``````Sub Highlight()
Â Â Â  Dim xRg1 As Range
Â Â Â  Dim xRg2 As Range
Â Â Â  Dim xTxt As String
Â Â Â  Dim xCell1 As Range
Â Â Â  Dim xCell2 As Range
Â Â Â  Dim I As Long
Â Â Â  Dim J As Integer
Â Â Â  Dim xLen As Integer
Â Â Â  Dim xDiffs As Boolean
Â Â Â  On Error Resume Next
Â Â Â  If ActiveWindow.RangeSelection.Count > 1 Then
Â Â Â Â Â  xTxt = ActiveWindow.RangeSelection.AddressLocal
Â Â Â  Else
Â Â Â Â Â  xTxt = ActiveSheet.UsedRange.AddressLocal
Â Â Â  End If
lOne:
Â Â Â  Set xRg1 = Application.InputBox("Range A:", "Select Range", xTxt, , , , , 8)
Â Â Â  If xRg1 Is Nothing Then Exit Sub
Â Â Â  If xRg1.Columns.Count > 1 Or xRg1.Areas.Count > 1 Then
Â Â Â Â Â Â Â  MsgBox "Multiple ranges or columns have been selected ", vbInformation, "Similar or Not"
Â Â Â Â Â Â Â  GoTo lOne
Â Â Â  End If
lTwo:
Â Â Â  Set xRg2 = Application.InputBox("Range B:", "Select Range", "", , , , , 8)
Â Â Â  If xRg2 Is Nothing Then Exit Sub
Â  Â Â If xRg2.Columns.Count > 1 Or xRg2.Areas.Count > 1 Then
Â Â Â Â Â Â Â  MsgBox "Multiple ranges or columns have been selected ", vbInformation, "Similar or Not"
Â Â Â Â Â Â Â  GoTo lTwo
Â Â Â  End If
Â Â Â  If xRg1.CountLarge <> xRg2.CountLarge Then
Â Â Â Â Â Â  MsgBox "Two selected ranges must have the same numbers of cells ", vbInformation, "Similar or Not"
Â Â Â Â Â Â  GoTo lTwo
Â Â Â  End If
Â Â Â  xDiffs = (MsgBox("Click Yes to highlight similarities, click No to highlight differences ", vbYesNo + vbQuestion, "Similar or Not") = vbNo)
Â Â Â  Application.ScreenUpdating = False
Â Â Â  xRg2.Font.ColorIndex = xlAutomatic
Â Â Â  For I = 1 To xRg1.Count
Â  Â Â Â Â Â Â Set xCell1 = xRg1.Cells(I)
Â Â Â Â Â Â Â  Set xCell2 = xRg2.Cells(I)
Â Â Â Â Â Â Â  If xCell1.Value2 = xCell2.Value2 Then
Â Â Â Â Â Â Â Â Â Â Â  If Not xDiffs Then xCell2.Font.Color = vbRed
Â Â Â Â Â Â Â  Else
Â Â Â Â Â Â Â Â Â Â Â  xLen = Len(xCell1.Value2)
Â Â Â Â Â Â Â Â Â Â Â  For J = 1 To xLen
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  If Not xCell1.Characters(J, 1).Text = xCell2.Characters(J, 1).Text Then Exit For
Â Â Â Â Â Â Â Â Â Â Â  Next J
Â Â Â Â Â Â Â Â Â Â Â  If Not xDiffs Then
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  If J <= Len(xCell2.Value2) And J > 1 Then
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  xCell2.Characters(1, J - 1).Font.Color = vbRed
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  End If
Â Â Â Â Â Â Â Â Â Â Â  Else
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  If J <= Len(xCell2.Value2) Then
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  xCell2.Characters(J, Len(xCell2.Value2) - J + 1).Font.Color = vbRed
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  End If
Â Â Â Â Â Â Â Â Â Â Â  End If
Â Â Â Â Â Â Â  End If
Â Â Â  Next
Â Â Â  Application.ScreenUpdating = True
End Sub``````
• Then, open the macro from the Developer tab by clicking on Macros.

• Now, in the Macro window, select the Highlight macro and click Run.

• After that, insert the first range in the Select Range window and click OK.

• Next, select the second range and again click OK.

• Here, press Yes to confirm.

• As a result, the VBA code will highlight a similar value in cell C8.

## Conclusion

I hope that you were able to apply the methods that I showed in this tutorial on how to compare two strings for similarity in excel. As you can see, there are quite a few ways to achieve this. So wisely choose the method that suits your situation best. If you get stuck in any of the steps, I recommend going through them a few times to clear up any confusion. If you have any queries, please let me know in the comments.

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

Get FREE Advanced Excel Exercises with Solutions!
Shakil Ahmed

My nameâ€™s Shakil. My articles are targeted to support you in enriching knowledge regarding different features related to Microsoft Excel. I am fond of literature, hope some knowledge from them will help me providing you some engaging articles even though some weary technical terms.

We will be happy to hear your thoughts

Advanced Excel Exercises with Solutions PDF