VBA & Macro Problems

How to Make an Excel Cell Editable Based on a Dropdown Selection

Algirdas JasaitisAlgirdas Jasaitis Nov 2, 2026 870 views

Question details

The user needs an Excel cell to automatically insert a formula when a specific dropdown value is selected, but clear itself to allow manual data entry when a different value is chosen.

How to Make an Excel Cell Editable Based on a Dropdown Selection
Product
Excel
Device & OS
not provided
Scenario
Automating cell content behavior based on a dropdown list selection to toggle between a calculated formula and a blank, editable state.
Observed behavior
A standard formula alone cannot clear itself to allow manual entry and then restore itself automatically. The user needs to implement a VBA macro to handle this dynamic switch.
Before you start

Ensure that the Developer tab is visible in your Excel ribbon and that you are familiar with saving files in the Macro-Enabled Workbook (.xlsm) format.

Solution 1Recommended

Use the Worksheet Change Event in VBA

Use a VBA macro to automatically insert a formula or clear the cell contents based on the value selected in the dropdown.

Excel formulas cannot automatically overwrite themselves or switch states dynamically without being permanently erased by manual entry. To achieve this toggle effect, you need to use a Worksheet_Change event in VBA. Note that enabling macros is required for this solution to work.

1
Open the VBA Editor

Right-click the specific worksheet tab at the bottom of your Excel window and select 'View Code' from the context menu. This will open the Microsoft Visual Basic for Applications (VBA) editor directly into the correct module.

2
Insert the VBA Code

Copy and paste the following code into the blank worksheet module window: Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("H5"), Target) Is Nothing Then Application.EnableEvents = False Select Case Range("H5").Value Case "1:1" Range("K5").Formula = "=K2" Case Else Range("K5").ClearContents End Select Application.EnableEvents = True End If End Sub

3
Test the Dropdown

Close the VBA editor and switch back to Excel. Try changing the value in your dropdown cell (H5). When you select '1:1', cell K5 will populate with the formula '=K2'. When you select anything else, K5 will clear itself, allowing you to type manually.

4
Save as a Macro-Enabled Workbook

To preserve the VBA code, go to 'File' > 'Save As'. In the 'Save as type' dropdown, select 'Excel Macro-Enabled Workbook (*.xlsm)' and click Save. Make sure you allow macros the next time you open the file.

Use the Worksheet Change Event in VBA
Protecting the Formula Cell: If K5 contains a formula, the user can still overwrite it with a value. If you want to prevent that while '1:1' is selected, you should protect the worksheet and lock/unlock K5. This would require adding ActiveSheet.Unprotect and ActiveSheet.Protect lines into the VBA code.
Advanced Automation

Automate Cells with Macros in WPS Spreadsheet

WPS Spreadsheet fully supports VBA macros, allowing you to easily automate cell changes and manage dropdown-dependent inputs just like Microsoft Excel.

  1. 1. Access the Developer Tab: Open your workbook in WPS Spreadsheet and navigate to the Developer tab on the top ribbon.
  2. 2. Open the VBA Editor: Click on the 'VBA Editor' icon to access the coding environment and double-click the specific Sheet object in the Project Explorer.
  3. 3. Paste and Save: Paste your Worksheet_Change event code, close the editor, and save your document as a Macro-Enabled Workbook (.xlsm) directly within WPS Office.
Fully compatible with Microsoft Excel (.xlsx and .xlsm) formats.Supports VBA macros for advanced automation and dynamic cell updates.Lightweight and free to use.Familiar interface with a built-in Developer tab for quick code editing.
microsoft office alternative - wps office

Frequently Asked Questions

Why can't I use an IF statement formula instead of VBA?

An IF formula can display different values based on a dropdown selection, but it cannot make a cell truly blank for manual entry without the user typing over the formula. Once a user types over the IF formula, the formula is permanently deleted and won't return if the dropdown changes. VBA is required to rewrite the formula automatically.

How do I enable the Developer tab to use VBA?

Go to File > Options > Customize Ribbon. In the right pane under 'Main Tabs', check the box next to 'Developer' and click OK. The Developer tab will now be visible on your main ribbon.

Why isn't my VBA code working when I change the dropdown?

Ensure that macros are enabled in your Trust Center settings. Additionally, check that the code was placed in the specific Worksheet module (e.g., Sheet1) by right-clicking the sheet tab and selecting 'View Code'. The code will not run automatically if it is placed in a standard Module.

How do I adjust the VBA code for different cell addresses?

In the provided code, change "H5" to the cell reference that contains your dropdown list, and change "K5" to the cell where you want the formula or manual entry to happen. Also, update "=K2" to whatever specific formula you need.