VBA & Macro Problems

How to Use VBA Range.Find to Color Multiple Matching Values in Excel

Khadija KhanKhadija Khan Oct 29, 2026 871 views

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.

How to Color Multiple Matching Values Using VBA in Excel
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.
Before you start

Ensure you have the Developer tab enabled in your Excel ribbon and have backed up your workbook before running any new VBA macros.

Solution 1Recommended

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.

1
Open the VBA Editor

Press ALT + F11 to open the Visual Basic for Applications (VBA) editor in Excel.

2
Insert a New Module

Click 'Insert' from the top menu and select 'Module' to create a blank script window.

3
Define the Macro to Color Matches

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').

4
Loop to Remove Excluded Colors

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'.

5
Run the Macro

Press F5 or go to Run > Run Sub/UserForm to execute the macro and apply your formatting.

Color the Target Range and Remove Color from Excluded Cells
Scalability Advantage: This subtractive method avoids maintaining a long, hardcoded list of every possible included suffix in your VBA code.
Advanced Macro Support in WPS

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. 1. Open your Workbook in WPS: Launch WPS Spreadsheet and open your .xlsm or .xlsb file containing the macro.
  2. 2. Access the Developer Tools: Navigate to the 'Tools' or 'Developer' tab on the ribbon and click on 'Macros' or 'VBA Editor'.
  3. 3. Run Your Code: Select your range coloring macro and click 'Run' to instantly highlight and exclude the target values.
Fully compatible with Microsoft Excel VBA syntax and macro files (.xlsm).Easily run Range.Find and color index manipulation scripts.Lightweight application that opens large macro-enabled workbooks quickly.Free basic features with affordable advanced macro options.
microsoft office alternative - wps office

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.