logo
search
VBA & Macro Problems

How to Check if a Cell is TRUE and Clear Other Cells Using Excel VBA

Camila MilosovichCamila Milosovich Oct 21, 2026 868 views

Question details

The user wants to use an Excel VBA macro to evaluate if a specific cell contains the value TRUE and automatically clear the contents of a different cell range based on that condition.

How to Check if a Cell is TRUE and Clear Other Cells Using Excel VBA
Product
Excel
Device & OS
not provided
Scenario
Automating data clearing based on specific boolean cell conditions.
Observed behavior
The goal is to successfully execute a VBA macro that checks a cell's state and clears other designated cells if the state is TRUE.
Before you start

Ensure that your Excel workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled the Developer tab in your ribbon to access the VBA editor.

Solution 1Recommended

Use an IF Statement in VBA to Clear Target Range

Write a simple VBA macro using an IF statement to evaluate the condition of a cell and clear the target range if the condition is met.

This method uses a standard VBA conditional statement to check the boolean value of a specific cell (like A1). If the condition is met, the .Clear method is applied to a designated range (like B1:B3).

1
Open the VBA Editor

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

2
Insert a New Module

In the top menu, go to Insert > Module to create a new blank macro module.

3
Paste the VBA Code

Copy and paste the following code into the module window: Sub SpecificCell() If Range("A1") = True Then Range("B1:B3").Clear End If End Sub

4
Run the Macro

Press F5 or go to Run > Run Sub/UserForm in the top menu to execute the macro. If cell A1 contains TRUE, the contents and formatting of cells B1 to B3 will be cleared.

Use an IF Statement in VBA to Clear Target Range
Clear vs ClearContents: Using the .Clear method removes both the cell contents and the cell formatting. If you only want to remove the data but keep your formatting intact, change the code to use Range("B1:B3").ClearContents instead.
Automate with WPS Spreadsheet

Run VBA Macros to Clear Cells in WPS Spreadsheet

WPS Office offers robust support for VBA macros, allowing you to automate repetitive tasks like checking cell values and clearing contents just as you would in Microsoft Excel.

  1. 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your .xlsm workbook.
  2. 2. Navigate to the Developer Tab: Click on the Developer tab on the top ribbon.
  3. 3. Access the VBA Editor: Click on Visual Basic or press Alt + F11 to open the VBA Editor.
  4. 4. Insert the Macro Code: Go to Insert > Module and paste your IF statement code to check for TRUE values.
  5. 5. Run to Automate: Run the macro to automatically clear your target cells based on the condition.
Fully compatible with Microsoft Excel macro formats (.xlsm).Supports standard VBA syntax for logical checks and cell manipulation.Lightweight application that runs smoothly on all devices.Familiar ribbon interface for a seamless transition without a learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

How do I check if a cell is FALSE instead of TRUE?

Simply change the condition in your VBA code to `If Range("A1") = False Then`. This will trigger the clear action when the cell contains the value FALSE.

Can I clear cells on a different worksheet?

Yes, you can specify the worksheet in your VBA code. For example: `If Worksheets("Sheet1").Range("A1") = True Then Worksheets("Sheet2").Range("B1:B3").Clear`.

Why is my VBA macro not running?

Macros might be disabled by your software security settings. Go to the Developer tab, click on Macro Security, and enable macros. Additionally, ensure your file is saved as a Macro-Enabled Workbook (.xlsm).