logo
search
VBA & Macro Problems

How to Select Conditional Formatting Only on the Current Excel Sheet Using VBA

Aamir Naveed AkramAamir Naveed Akram Oct 22, 2026 868 views

Question details

The user wants to use a VBA macro to select all cells containing conditional formatting, but the selection must be strictly limited to the current active worksheet rather than the entire workbook.

How to Select Conditional Formatting Only on the Current Excel Sheet Using VBA
Product
Excel
Device & OS
not provided
Scenario
Writing a VBA macro script to manage conditional formatting efficiently on a single active sheet without affecting background sheets.
Observed behavior
The standard VBA method needs to be scoped correctly to the ActiveSheet so that the SpecialCells method does not perform a global workbook search.
Before you start

Ensure you have enabled the Developer tab in your spreadsheet application to access the VBA editor, and save a backup of your workbook before testing new macros.

Solution 1Recommended

Use the SpecialCells Method on ActiveSheet.Cells

Apply the SpecialCells method specifically to the cells of the active worksheet to limit the conditional formatting selection to the current sheet.

Applying SpecialCells directly without specifying the cell range on the active sheet might not properly restrict the operation. By explicitly adding '.Cells' after 'ActiveSheet', the macro accurately evaluates only the cells within your currently viewed worksheet.

1
Open the VBA Editor

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

2
Insert a New Module

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

3
Enter the Macro Code

Type or paste the following code into the module window: Sub selectingconditionalformatting() ActiveSheet.Cells.SpecialCells(xlCellTypeAllFormatConditions).Select End Sub

4
Run the Macro

Press F5 or click the 'Run' button in the toolbar. The macro will immediately select all cells containing conditional formatting rules on your active sheet.

Use the SpecialCells Method on ActiveSheet.Cells
Targeted Selection: This targeted approach prevents the macro from accidentally selecting or processing conditional formatting cells in other hidden or inactive sheets within your workbook.
Advanced VBA Support

Run VBA Macros Seamlessly in WPS Office Spreadsheets

WPS Spreadsheets provides robust support for VBA macros, allowing you to run, edit, and manage your Excel scripts effortlessly. Easily select conditional formatting or automate complex tasks within a highly familiar interface.

  1. 1. Download WPS Office: Download and install WPS Office for free from the official website.
  2. 2. Open your Workbook: Open your macro-enabled Excel workbook (.xlsm or .xlsx) in WPS Spreadsheets.
  3. 3. Access the Developer Tab: Go to the 'Tools' tab and click 'Developer' to launch the integrated VBA Editor.
  4. 4. Run Your Macro: Paste and run your ActiveSheet.Cells VBA code exactly as you would in Microsoft Excel.
Fully compatible with Microsoft Excel .xls, .xlsx, and .xlsm formats.Built-in VBA editor perfectly supports SpecialCells and other standard macro functions.Lightweight installation footprint with lightning-fast performance.Familiar ribbon interface that requires zero learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

What happens if there is no conditional formatting on the active sheet when running the macro?

If you run the macro and no cells contain conditional formatting, the VBA code will trigger a 'No cells were found' runtime error. To prevent this, you can add the statement 'On Error Resume Next' right before the selection line in your code.

Can I assign this conditional formatting VBA macro to a clickable button?

Yes. You can insert a shape or a form control button from the Developer or Insert tab, right-click the object, select 'Assign Macro', and choose your 'selectingconditionalformatting' macro to run it with a single click.

How do I modify the code to select only a specific type of conditional format?

The xlCellTypeAllFormatConditions constant selects all conditional formats regardless of type. To select a specific type (e.g., only color scales or databars), you would need to write a more complex macro that iterates through the FormatConditions collection using a loop, as SpecialCells alone cannot filter by rule type.

Is WPS Office completely compatible with Microsoft Excel VBA macros?

Yes, WPS Office Pro and versions with VBA extensions enabled fully support standard Excel VBA. You can run macros utilizing ActiveSheet, SpecialCells, and standard object models without needing to rewrite your code.