How to Use VBA Range.Find to Color Multiple Matching Values in Excel
Question details
The user needs an Excel VBA macro to highlight cells containing specific matching string patterns while excluding a specific variant, accommodating future additions automatically.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Highlighting dynamically matching values using an Excel VBA macro.
- Observed behavior
- Needs a maintainable way to color cells like 'Overhead', 'Overhead - A', etc., but exclude 'Overhead C' without hardcoding every included suffix.
Ensure you have the Developer tab enabled in your Excel ribbon and have backed up your workbook before running any new VBA macros.
Color the Target Range and Remove Color from Excluded Cells
Instead of finding and coloring every matching variation individually, color the general matching range first and then loop through to remove the color from the specific excluded values.
This approach is highly scalable. By coloring all matching cells initially (e.g., using a general find for 'Overhead') and then clearing the format for specific exclusions (e.g., 'Overhead C'), you do not need to update your VBA code every time a new suffix like 'Overhead - D' is added.
Press ALT + F11 to open the Visual Basic for Applications (VBA) editor in Excel.
Click 'Insert' from the top menu and select 'Module' to create a blank script window.
Write a script that first finds the general term and applies the desired interior color to those cells, creating a defined range variable (e.g., 'TargetRange').
Add a For Each loop to iterate through the colored range: 'For Each cell In TargetRange.Cells: If cell.Value = "Overhead C" Then cell.Interior.ColorIndex = xlColorIndexNone: Next cell'.
Press F5 or go to Run > Run Sub/UserForm to execute the macro and apply your formatting.

Execute VBA Macros Seamlessly in WPS Spreadsheet
WPS Spreadsheet fully supports VBA macros, allowing you to run complex automation scripts like conditional coloring and range finding without modifying your existing Excel code.
- 1. Open your Workbook in WPS: Launch WPS Spreadsheet and open your .xlsm or .xlsb file containing the macro.
- 2. Access the Developer Tools: Navigate to the 'Tools' or 'Developer' tab on the ribbon and click on 'Macros' or 'VBA Editor'.
- 3. Run Your Code: Select your range coloring macro and click 'Run' to instantly highlight and exclude the target values.

Frequently Asked Questions
Can I use Conditional Formatting instead of VBA for this?
Yes, you can use Conditional Formatting with custom formulas (e.g., using SEARCH and NOT functions) to highlight cells containing specific text while excluding others, which may be simpler than VBA for non-developers.
What does xlColorIndexNone do in Excel VBA?
xlColorIndexNone is a VBA constant used to clear the interior fill color of a cell, returning it to a transparent or 'no fill' state.
How do I make my Range.Find look at partial cell values?
When using Range.Find in VBA, set the LookAt parameter to xlPart instead of xlWhole. This ensures the macro finds cells containing the string, even if other characters are present.
Will this macro automatically run when I type new data?
Not natively. To make the macro run automatically upon data entry, you need to place your code inside the Worksheet_Change event for that specific sheet.




