Excel Formula for Fuzzy String Matching and Similarity Score Indexing

📅 Jul 24, 2026 📝 Sarah Miller

Reconciling inconsistent text data in Excel is a notoriously tedious bottleneck for analysts. While relying on exact-match functions represents a standard analytical investment-similar to securing traditional funding sources for highly structured projects-these rigid tools fail when confronted with typos. Emphasizing fuzzy matching grants your team the unique ability to automate near-matches, saving hours of manual audit. However, the stipulation is that similarity thresholds must be carefully calibrated to prevent false positives. Utilizing tools like Power Query's Jaccard Index serves as a proven framework. Below, we outline the exact formulas to index these matches and calculate precise similarity scores.

Excel Formula for Fuzzy String Matching and Similarity Score Indexing

Excel Formula to Index Fuzzy Matched Strings with Similarity Scores

Data analysts often encounter the frustrating challenge of merging datasets with inconsistent text entries. Whether it is a typo ("John Smith" vs. "Jon Smith"), an abbreviation ("Apple Corp" vs. "Apple Corporation"), or minor spacing issues, standard lookup functions like VLOOKUP, XLOOKUP, or INDEX/MATCH fall short because they demand exact matches. To bridge this gap, you need fuzzy matching.

In this comprehensive guide, we will explore how to index fuzzy matched strings and calculate their similarity scores in Excel. We will cover three robust methods: using VBA (User Defined Functions) for formulaic flexibility, utilizing Power Query for code-free automation, and leveraging Python in Excel for cutting-edge data science capabilities.


Understanding the Logic: How Fuzzy Matching Works

Fuzzy matching relies on mathematical algorithms to determine how "close" two text strings are to each other. The most common metric is the Levenshtein Distance (or Edit Distance), which counts the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one word into another.

To turn this distance into a readable Similarity Score, we normalize it against the length of the strings using the following formula:

Similarity Score = 1 - (Levenshtein Distance / Max Length of Both Strings)

A score of 1.0 (or 100%) indicates an exact match, while a score of 0.0 indicates completely different strings.


Method 1: VBA Levenshtein Distance & Custom Excel Formulas

If you need dynamic formulas that update automatically when cells change, building a custom VBA function is the most reliable path. Follow these steps to implement a Levenshtein-based lookup in your workbook.

Step 1: Insert the VBA Code

Press ALT + F11 to open the VBA Editor. Click Insert > Module and paste the following code:

Function LevenshteinSimilarity(ByVal string1 As String, ByVal string2 As String) As Double
    Dim len1 As Integer, len2 As Integer
    Dim matrix() As Integer
    Dim i As Integer, j As Integer
    Dim cost As Integer
    
    string1 = LCase(Trim(string1))
    string2 = LCase(Trim(string2))
    
    len1 = Len(string1)
    len2 = Len(string2)
    
    If len1 = 0 Then
        LevenshteinSimilarity = IIf(len2 = 0, 1#, 0#)
        Exit Function
    End If
    If len2 = 0 Then
        LevenshteinSimilarity = 0#
        Exit Function
    End If
    
    ReDim matrix(0 To len1, 0 To len2)
    
    For i = 0 To len1: matrix(i, 0) = i: Next i
    For j = 0 To len2: matrix(0, j) = j: Next j
    
    For i = 1 To len1
        For j = 1 To len2
            If Mid(string1, i, 1) = Mid(string2, j, 1) Then
                cost = 0
            Else
                cost = 1
            End If
            matrix(i, j) = Application.WorksheetFunction.Min( _
                matrix(i - 1, j) + 1, _
                matrix(i, j - 1) + 1, _
                matrix(i - 1, j - 1) + cost)
        Next j
    Next i
    
    Dim maxLen As Integer
    maxLen = IIf(len1 > len2, len1, len2)
    
    LevenshteinSimilarity = 1 - (matrix(len1, len2) / maxLen)
End Function

Step 2: Apply the Formula in Your Worksheet

Assume you have a lookup value in cell A2, and you want to search through a list of master names in the range $D$2:$D$100 to find the closest match and pull its corresponding ID from $E$2:$E$100.

With Excel 365, you can write a single dynamic array formula to find the best match and output both the match and the score:

To find the best matched string:

=INDEX($D$2:$D$100, MATCH(MAX(MAP($D$2:$D$100, LAMBDA(x, LevenshteinSimilarity(A2, x)))), MAP($D$2:$D$100, LAMBDA(x, LevenshteinSimilarity(A2, x))), 0))

To return the highest Similarity Score:

=MAX(MAP($D$2:$D$100, LAMBDA(x, LevenshteinSimilarity(A2, x))))

How it works: The MAP function runs our custom LevenshteinSimilarity VBA function across every item in the target range. MAX identifies the highest score, and MATCH locates the row index of that score to feed into the INDEX function.


Method 2: Code-Free Fuzzy Matching with Power Query

If you are working with large datasets and prefer not to deal with VBA, Excel's built-in Power Query engine offers native fuzzy matching capability that is extremely powerful and easy to configure.

Step-by-Step Power Query Setup:

  1. Select your source table, go to the Data tab, and click From Sheet / Table/Range. Do the same for your master/lookup table.
  2. In the Power Query Editor, with your main table selected, click on Merge Queries in the Home tab.
  3. In the Merge dialog, select your secondary table from the drop-down menu.
  4. Click on the columns from both tables that you want to match (e.g., "Customer Name").
  5. Check the box that says "Use fuzzy matching to perform the merge".
  6. Expand the Fuzzy matching options drop-down:
    • Similarity threshold: Set this between 0.00 and 1.00 (0.80 is generally the sweet spot).
    • Ignore case: Check this to ensure capitalization differences do not affect matches.
    • Match by combining parts: Useful for matching "John Smith" with "Smith, John".
  7. Click OK. Expand the merged table column to extract the matched string. Go to Close & Load to return your merged data to Excel.

Method 3: Python in Excel (The Modern Approach)

For users with access to modern Microsoft 365 environments, Python in Excel introduces native, enterprise-grade string matching tools like the difflib module from Python's standard library.

The Python Formula:

Type =PY in an empty cell to activate the Python formula bar, and input the following script:

import difflib
# Reference your target value and lookup list
target_val = xl("A2")
lookup_list = xl("D2:D100")[0].tolist()
# Find the closest match and compute score
best_match = difflib.get_close_matches(target_val, lookup_list, n=1, cutoff=0.0)
if best_match:
    match_str = best_match[0]
    score = difflib.SequenceMatcher(None, target_val, match_str).ratio()
    result = [match_str, round(score, 4)]
else:
    result = ["No Match", 0.0]
result

This Python code returns an array containing both the best matched string and its exact similarity score as calculated by the highly optimized Gestalt Pattern Matching algorithm. You can split this array into adjacent cells to quickly display your clean data alongside its match confidence rating.


Comparing the Three Methods

Feature / Metric Method 1: VBA Formulas Method 2: Power Query Method 3: Python in Excel
Ease of Setup Moderate (requires copying VBA) Easy (GUI-driven wizard) Easy (requires Python-enabled Excel)
Performance Slow on large datasets Fast (optimized for big data) Very Fast (runs in cloud container)
Dynamic Updates Instant (recalculates on edit) Requires manual query refresh Instant (recalculates on edit)
Customizability High (editable VBA code) Moderate (standard parameters) Extremely High (access to Python libraries)

Best Practices for Fuzzy Match Clean-up

Regardless of the method you choose, keep these tips in mind to achieve the highest accuracy:

  • Standardize first: Run basic clean-up on your columns before matching. Remove trailing/leading spaces (using TRIM) and non-printable characters (using CLEAN).
  • Establish a Cutoff Threshold: Do not blind-trust matches. Filter your final outputs by their similarity scores; anything with a score below 0.75 (75%) should be manually reviewed by a human operator.
  • Index auxiliary data: Once you have established the matched string using fuzzy methods, always use an exact-match index function (like XLOOKUP) to pull auxiliary data (such as Account Balances or Phone Numbers) to prevent rounding or string evaluation mismatches.

By implementing these fuzzy-match techniques, you can transform hours of manual text editing into automated, structured, and auditable data operations.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.