How to Automatically Clear an Excel Cell When New Data Is Added
Question details
The user wants to configure Excel so that when a new value is entered into one specific cell, the contents of another related cell are automatically cleared.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Automating data entry forms or interconnected spreadsheet cells where updating a primary response requires resetting an associated target cell.
- Observed behavior
- The user needs a reliable method to monitor a designated input cell and trigger a clear action on a secondary cell instantly using VBA.
Ensure that the Developer tab is enabled in your spreadsheet ribbon, and remember that you must save your workbook as a Macro-Enabled file (.xlsm) to keep the VBA code active.
Use a VBA Worksheet_Change Event Macro
Adding a background VBA script to your worksheet allows Excel to monitor a target cell and instantly clear another cell when new data is detected.
The Worksheet_Change event triggers automatically whenever a user alters a cell's value on that specific sheet. By combining this with an 'If' statement, you can restrict the action to trigger only when a specific response cell is modified.
Press the Alt + F11 keys on your keyboard simultaneously to launch the Visual Basic for Applications (VBA) editor.
In the Project Explorer pane on the left, locate your current workbook. Double-click on the specific worksheet name (e.g., Sheet1) where you want this automation to occur.
In the blank code window that opens, paste the following script: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$B$2" Then Range("C2").ClearContents End If End Sub
Modify the code to fit your data. Replace "$B$2" with the cell you are typing the new data into, and replace "C2" with the cell you want to be cleared automatically.
Close the VBA editor. Go to File > Save As, and choose 'Excel Macro-Enabled Workbook (*.xlsm)' from the format dropdown. If you save as a standard .xlsx, the macro will be deleted.

Run Macros Seamlessly in WPS Office Spreadsheets
WPS Office offers robust support for VBA macros and is fully compatible with Excel's .xlsm files. You can write, edit, and execute Worksheet_Change events to automate data clearing tasks with the same powerful Visual Basic Editor found in Excel.
- 1. Open your Workbook in WPS Spreadsheet: Launch WPS Office and open your data entry spreadsheet.
- 2. Enable the Developer Tools: Navigate to the 'Developer' tab on the top ribbon and click the 'VB Editor' button (or press Alt+F11).
- 3. Paste the Auto-Clear Script: Double-click your active sheet in the left menu, paste the Worksheet_Change macro code, and customize the target cells.
- 4. Save with Macro Support: Go to Menu > Save As, and select 'Microsoft Excel Macro-Enabled Workbook (*.xlsm)' to preserve your automation.

Frequently Asked Questions
Can I clear multiple cells instead of just one when data changes?
Yes. You can expand the range in your VBA code. Instead of Range("C2").ClearContents, use Range("C2:E2").ClearContents to clear a contiguous block, or Range("C2, E2, G2").ClearContents to clear non-adjacent cells.
Why is my VBA macro not triggering when I enter new data?
Macros might be disabled in your application's Trust Center security settings. Ensure you click 'Enable Content' if a security warning appears at the top of your sheet. Additionally, confirm that the file was saved as an .xlsm macro-enabled file.
How can I monitor an entire column for changes rather than a single cell?
You can use the Intersect method in your VBA script. Replace 'If Target.Address = "$B$2"' with 'If Not Intersect(Target, Range("B:B")) Is Nothing Then'. This will trigger the cell-clearing action anytime a modification happens anywhere within Column B.




