VBA & Macro Problems

How to Show or Hide Excel Rows Based on Multiple Drop-Down Selections

Khadija KhanKhadija Khan Nov 11, 2026 870 views

Question details

The user wants to automatically show or hide specific rows in a spreadsheet based on multiple selections made in a drop-down list cell.

How to Show or Hide Excel Rows Based on Multiple Drop-Down Selections
Product
Excel
Device & OS
not provided
Scenario
Creating an interactive spreadsheet where selecting multiple items in a single drop-down cell dynamically filters or adjusts the visible rows to match the selected items.
Observed behavior
Specific rows need to dynamically update their hidden property whenever the multi-select drop-down is modified, while preserving the previously selected values in the cell.
Before you start

Ensure that your workbook is saved as an Excel Macro-Enabled Workbook (.xlsm) and that you have enabled macros in your Trust Center settings.

Solution 1Recommended

Use a Worksheet_Change VBA Event

Apply a VBA script to automatically handle multiple selections in a drop-down and toggle row visibility based on the cell's content.

This solution uses the Worksheet_Change event triggered whenever your target cell (e.g., cell B12) is modified. It temporarily disables screen updating and application events to prevent infinite loops and performance issues.

The code first preserves multiple selections separated by commas within the cell, and then loops through the target rows (e.g., rows 16 to 23) to hide or show them depending on whether the corresponding claim text appears in the drop-down cell.

1
Open the VBA Editor

Press 'Alt + F11' in your Excel workbook to open the Visual Basic for Applications (VBA) editor.

2
Access the Target Worksheet

In the Project Explorer pane on the left side of the editor, double-click the name of the worksheet containing your drop-down list (e.g., Sheet1).

3
Insert the VBA Code

Copy and paste your Worksheet_Change script into the code window. Ensure the code references your specific drop-down cell (like Range("B12")) and uses an appropriate For loop to set the .EntireRow.Hidden property for your target rows.

4
Save and Test

Close the VBA editor, save the file as a Macro-Enabled Workbook (.xlsm), and select multiple items in your target cell to verify that the correct rows are dynamically hidden or displayed.

Use a Worksheet_Change VBA Event
VBA Code Adjustments: You can customize the 'For i = ...' loop and the row offset in the script to target different rows based on your specific dataset layout.

Automate Spreadsheets Easily with WPS Office

WPS Office provides robust support for VBA and macros, allowing you to run complex automated scripts like showing and hiding rows based on drop-down selections exactly as you would in Microsoft Excel.

  1. 1. Download and Install: Download WPS Office for free from the official website and install it on your device.
  2. 2. Open Your Macro Workbook: Launch WPS Spreadsheets and open your .xlsm file containing the drop-down list.
  3. 3. Enable Macros: If prompted by the security warning at the top of the sheet, click 'Enable Macros' to allow the VBA scripts to run.
  4. 4. Run Your Automation: Make your selections in the drop-down cell and watch the rows hide or show automatically.
Seamlessly compatible with Microsoft Excel (.xlsx and .xlsm) file formats.Built-in support for standard VBA macros and Worksheet_Change events.Lightweight and runs smoothly on older devices without lagging.Free to download with a familiar, easy-to-use tabbed interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my Worksheet_Change event causing Excel to crash or freeze?

If you change a cell value within a Worksheet_Change event, it can re-trigger the event itself, causing an infinite loop. Always use 'Application.EnableEvents = False' before modifying cells in your VBA script, and set it back to 'True' right before the script ends.

Can I apply this VBA script to multiple drop-down cells at once?

Yes, you can modify the 'Intersect' function in the VBA code to check for multiple target cells by changing the range parameter (e.g., 'Range("B12, C12")') instead of checking just a single cell.

How do I create a multi-select drop-down list without using VBA?

Standard Data Validation drop-down lists in Excel natively only allow single selections. To enable multiple selections in a single cell, you are required to use a VBA Worksheet_Change event to append the new selection to the existing text.

Will this VBA row-hiding code work in WPS Office?

Yes, WPS Office Spreadsheets supports VBA and macros. You can run the exact same Worksheet_Change event code in WPS to hide or show rows dynamically, provided you save the file in a macro-enabled format.