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

Method 1 – Using Highlight Cells Rules Feature

Steps:

  • Select all the cells from B5 to C10.

selecting the cells to compare two strings for similarity in excel

  • Go to the Home tab and click on Conditional Formatting.
  • Go to Highlight Cells Rules and click on Duplicate Values.

highlight cells rules to compare two strings for similarity in excel

  • Click on OK.

  • This should highlight the values that are similar.


Method 2 – Applying New Rule Feature

Steps:

  • Select the cells from B5 to C10.

applying new rule feature to compare two strings for similarity in excel

  • Navigate to Conditional Formatting under the Home tab and click on New Rule.

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

  • Select a color under the Fill tab and click OK in this window and the next window.

  • This will highlight the values that are similar in the dataset.


Method 3 – Utilizing Equal Operator

Steps:

  • Go to cell D5 and insert the following formula:
=B5=C5

using equal operator to compare two strings for similarity in excel

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


Method 4 – Comparing Using EXACT Function

Steps:

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

using exact function to compare two strings for similarity in excel

  • Press the Enter key, and consequently, this will insert TRUE if the values are precisely similar.


Method 5 – Using SEARCH Function

Steps:

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

using search function to compare two strings for similarity in excel

  • Press the Enter key or click on any blank cell.
  • 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.

Method 6 – Applying VBA Code.

Steps:

  • Go to the Developer tab and select Visual Basic.

using VBA code to compare two strings for similarity in excel

  • Select Insert in the VBA window and click on Module.

  • 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
  • Open the macro from the Developer tab by clicking on Macros.

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

  • Insert the first range in the Select Range window and click OK.

  • Select the second range and again click OK.

  • Press Yes to confirm.

  • The VBA code will highlight a similar value in cell C8.


Handling Misspelled Names or Near Matches

In many real-world cases, users want to identify similar names that may have been entered with typos or slight variations (for example, Jonh Smith vs John Smith). Standard formulas like EXACT or =A1=B1 only detect perfect matches, so they will not help in these cases.

To handle this, you can try:

1. Fuzzy Lookup Add-In for Excel

  • Install Microsoft’s free Fuzzy Lookup Add-In.
  • It can compare two lists of names and return similarity scores, even if there are spelling differences.

2. SOUNDEX Function (VBA or Excel 365)

  • SOUNDEX converts text into a phonetic code, so similar-sounding names (like Sara and Sarah) can be matched.

3. Power Query Approximate Matching

  • Load your data into Power Query.
  • Use merge operations with fuzzy matching enabled to catch near-duplicates across different lists.

These tools make it easier to highlight names that are similar but not identical, which is often the real goal when working with customer lists, employee databases, or survey data.


Download Practice Workbook


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

Get FREE Advanced Excel Exercises with Solutions!
Shakil Ahmed
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.

6 Comments
  1. That’s not what similar means. Raspberries and Blackberries are similar. Movies and plays are similar. Foxes and dogs are similar. Two forks from the same set are not similar. The word implies a small degree of difference.

    • Hello Ric Esh,

      Thank you for sharing your perspective. In the context of comparing strings in Excel, the term “similar” is often used to describe how much two text values resemble each other, even if they are not exactly the same.
      While “similar” can imply some differences, in Excel functions it refers to the degree of likeness between two strings, which might include both small and significant differences depending on the method used.

      Regards
      ExcelDemy

  2. Gonna agree with another poster. I found this trying to find a way to handle detecting similar names, to highlight names that are merely misspellings introduced by input error.

    Nobody’s gonna google ‘compare strings for similarity’ when their goal is to identify perfect matches.

    • Hello Ashford,

      Thanks for pointing that out! Many times the real need is to catch misspelled or slightly different names rather than just exact string comparisons.
      We’ve updated the article with an extra section on handling near matches, including methods like Fuzzy Lookup, SOUNDEX, and Power Query fuzzy matching. Hopefully, that makes it more useful for cases like yours where input errors or typos need to be identified.

      Regards
      ExcelDemy

      • An advanced solution is a two-character Ngram comparison for Jaccard similarity. There are VBA solutions available, but it can be done formulaically.

        Here is my formula out of my Name Manager that I use for Jaccard similarity; I named it Jaccard, letting me use =Jaccard(A1,B1) to compare strings. This will score compared values with a decimal from zero to one, giving you a fuzzy judgement of similarity, and letting the user determine what math or conditional formatting to apply to highlight the degree of similarity they find useful.

        =LAMBDA(x,y, IF(OR(LEN(x)<2,LEN(y)<2),0,LET( a, UNIQUE(MID(x, SEQUENCE(LEN(x)-1), 2)), b, UNIQUE(MID(y, SEQUENCE(LEN(y)-1), 2)), inter, SUM(–ISNUMBER(MATCH(a,b,0))), uni, ROWS(UNIQUE(VSTACK(a,b))), inter/uni )))

        Here is a slimmer version, stripped of some legibility formatting, the Lambda that's required for use in the Name Manager, and the LET formulas for intersections and unique sets(included for legibility, not strictly needed). This example is comparing cells X3 and Y3.

        =IF(OR(LEN(X3)<2,LEN(Y3)<2),0,LET(a,UNIQUE(MID(X3,SEQUENCE(LEN(X3)-1),2)),b,UNIQUE(MID(Y3,SEQUENCE(LEN(Y3)-1),2)),SUM(–ISNUMBER(MATCH(a,b,0)))/ ROWS(UNIQUE(VSTACK(a,b)))))

        Jaccard similarity basically breaks words into ngrams – usually of a length of two for short strings – then compare the number of unique shared ngrams with the number of total unique ngrams.

        For example, CATS is composed of the ngrams CA, AT, and TS, while SCAT is composed of the ngrams SC,CA, and AT. The unique ngrams are SC, CA, AT, and TS, and two are shared, so Jaccard similarity will score these as 50% similar.

        • Shamima Sultana
          Shamima Sultana Aug 22, 2025 at 9:08 PM

          Hello Ashford,

          That’s an excellent addition! Thank you for sharing the Jaccard similarity approach with both the detailed and slimmer formula versions.
          Using two-character n-grams for comparison is a clever way to capture fuzzy matches, and your example with CATS vs. SCAT makes it very clear.

          This will definitely help users who want a more advanced, formula-based alternative to VBA for comparing string similarity in Excel.

          Regards
          ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo