VBA & Macro Problems

Modify an Excel Cell Only When a Condition Is Met

Emma BrownEmma Brown Nov 18, 2026 870 views

Question details

Update an Excel cell when a condition is met and retain or reproduce its existing value otherwise.

Modify an Excel Cell Only When a Condition Is Met
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet should change a cell's value only when a specified condition is true.
Observed behavior
A formula can return a conditional result, but it cannot retain an arbitrary previous manual value when the condition is false.
Before you start

Identify the condition cell, the cell to update, and where the new value comes from. Determine whether the value needed when the condition is false can be recalculated from another cell or must be preserved as an arbitrary manual entry.

Solution 1

Use an IF Formula When the Original Value Can Be Recalculated

Use a formula if the value needed when the condition is false is available from another cell or calculation.

1
Set up the source cells

For example, use A2 for the condition, C2 for the new value, and D2 for the value to show when the condition is false.

2
Enter the formula

Select B2 and enter =IF(A2="Yes",C2,D2). B2 displays C2 when A2 is Yes and D2 otherwise.

3
Test both outcomes

Change A2 between Yes and another value and check that B2 displays the expected result.

Formula limitation: The formula in B2 replaces any manual value previously entered there. D2 must supply or calculate the value to display when the condition is false.
Free Microsoft Office alternative

Use WPS Spreadsheets for Conditional Formulas

WPS Office is a free, lightweight alternative with a familiar interface for working with spreadsheet formulas. Open compatible Excel files to migrate everyday spreadsheet work easily; Excel VBA event behavior may require Microsoft Excel.

Use IF formulas for conditional spreadsheet resultsOpen and edit compatible Microsoft Excel XLSX filesWork in a familiar spreadsheet interfaceUse a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Can an Excel formula keep a cell's previous manual value?

An ordinary formula cannot preserve an arbitrary previous manual value in the same cell. Use an IF formula if the fallback value can be calculated elsewhere, or use a VBA event macro if it must remain unchanged.

Where should I put the Worksheet_Change code?

In desktop Excel, right-click the worksheet tab, select View Code, and place the event procedure in that worksheet's code window. If a Worksheet_Change procedure already exists, combine the logic with it.

Why doesn't the macro run when a formula result changes?

Worksheet_Change responds to cell edits, not changes caused solely by formula recalculation. For a recalculation-driven condition, consider a Worksheet_Calculate event and account for repeated recalculations.

What file format should I use for the VBA solution?

Choose File > Save As and save the workbook as an Excel Macro-Enabled Workbook (*.xlsm). When reopening it, enable macros only if you trust the file.