VBA & Macro Problems

How to Use Partial Matching with VBA Find in Excel

John WilsonJohn Wilson Nov 2, 2026 870 views

Question details

The user needs to search for cells that contain a specific substring rather than an exact full-cell match using VBA.

How to Use Partial Matching with VBA Find in Excel
Product
Excel
Device & OS
not provided
Scenario
Automating a search task using Excel VBA where the target value is only part of the cell's contents, such as locating the word 'Business' inside 'Business Operations'.
Observed behavior
The default or current VBA Find configuration requires an exact match, failing to locate cells that contain additional text alongside the search string.
Before you start

Ensure your VBA editor is open (press Alt + F11) and locate the specific macro containing the Find method you wish to modify.

Solution 1Recommended

Modify the VBA Find Method Argument to xlPart

Change the LookAt argument in your VBA code to allow the macro to match cells containing the specified text anywhere within the cell.

The VBA Find method often defaults to the last used search setting, which might be set to match entire cell contents. By explicitly defining the LookAt argument in your code, you ensure the macro always performs a partial match regardless of previous searches.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor in Excel.

2
Locate your Find method

Find the module and the specific line of code where your Find method is executed.

3
Update the LookAt argument

Change the argument LookAt:=xlWhole to LookAt:=xlPart. If the LookAt argument is missing entirely, add , LookAt:=xlPart to your Find method parameters.

4
Run and test the macro

Save your changes and run the macro to verify that it successfully highlights or processes cells containing the partial string.

Modify the VBA Find Method Argument to xlPart
Testing the Macro: Always test your modified macro on a sample dataset first to ensure it highlights or selects the correct partial matches without unintended side effects.
Advanced VBA Support

Run VBA Macros Seamlessly in WPS Office

WPS Office provides robust support for VBA macros, allowing you to execute advanced scripting and partial matching tasks exactly like Microsoft Excel. Automate your workflow in a highly compatible environment.

  1. 1. Open your file in WPS: Launch WPS Spreadsheet and open your macro-enabled workbook.
  2. 2. Access the Developer Tools: Navigate to the Developer tab on the ribbon and click on the VBA Editor icon.
  3. 3. Modify the code: Locate your Find function and ensure the parameter is set to LookAt:=xlPart.
  4. 4. Execute the macro: Run the script directly within WPS Spreadsheet to successfully find your partial matches.
Fully compatible with Microsoft Excel (.xlsm) formats and standard VBA codeLightweight application that loads faster and runs scripts efficientlyFamiliar user interface that requires no steep learning curveComprehensive macro execution for automating complex data searches
microsoft office alternative - wps office

Frequently Asked Questions

Why is my VBA Find macro still looking for exact matches?

If the LookAt parameter is not explicitly defined in your code, Excel VBA inherits the setting from the last manual or programmatic search. Always declare LookAt:=xlPart to force partial matching.

Can I make the partial match case-sensitive?

Yes, you can enforce case sensitivity by adding the MatchCase argument to your Find method. Set it as MatchCase:=True to distinguish between uppercase and lowercase letters.

How do I find the next partial match in VBA?

To find subsequent partial matches, use the FindNext method in your VBA code after the initial Find method. This will continue searching the range using the previously defined xlPart parameter.