VBA & Macro Problems

How to Hide or Unhide Excel Columns Using a Drop-Down List and VBA

Emma BrownEmma Brown Nov 11, 2026 869 views

Question details

The user needs to dynamically control column visibility in a worksheet based on the selection made from a drop-down list using a VBA macro.

Hide or Unhide Excel Columns with a Drop-Down List and VBA
Product
Excel
Device & OS
not provided
Scenario
Managing large datasets where users only need to view data for specific categories, such as selecting an employee's name from a drop-down to display only their corresponding data columns while hiding the rest.
Observed behavior
Excel normally requires manual hiding and unhiding of columns. The user wants to automate this process so that changing a data validation drop-down selection instantly updates which columns are visible on the sheet.
Before you start

Ensure that your workbook is saved as a Macro-Enabled Workbook (.xlsm) so the VBA code will run, and verify that your Developer tab is visible to easily access the Visual Basic Editor.

Solution 1Recommended

Automate Column Visibility Using a Named Range and Application.Match

This method uses a named range for your column headers and a specific cell for the drop-down, providing a clean and easily adjustable VBA script that triggers automatically upon cell change.

By utilizing the Worksheet_Change event, Excel will constantly monitor the drop-down cell. Once a new value is selected, the macro matches the value against a named range, hides all columns in that range, and then unhides only the specific column that matches.

1
Set up the Drop-Down List

Select your control cell (e.g., G2), go to the Data tab, click Data Validation, and create a List containing your employee names or categories.

2
Create a Named Range

Highlight your data column headers, click into the Name Box (next to the formula bar), type 'Employee_List', and press Enter.

3
Open the VBA Editor

Right-click the current worksheet tab at the bottom of your screen and select 'View Code' to open the Visual Basic Editor for that specific sheet.

4
Insert the Worksheet_Change Code

Paste the following logic into the module: Set your range variable, use Application.Match to find the selected value, set rgList.EntireColumn.Hidden = True, and then set the matched column's EntireColumn.Hidden = False.

5
Test the Automation

Close the VBA editor and change the selection in your drop-down list in cell G2. The corresponding columns should now hide and unhide automatically.

Automate Column Visibility Using a Named Range and Application.Match
Macro Security: Make sure macros are enabled in your Trust Center settings, otherwise the Worksheet_Change event will not trigger.
Efficient Spreadsheet Management

Automate Your Spreadsheets with WPS Office

WPS Spreadsheet offers robust support for VBA macros and advanced data validation, allowing you to easily automate tasks like dynamically hiding and unhiding columns.

  1. 1. Set Up Data Validation: Open your workbook in WPS Spreadsheet, navigate to the 'Data' tab, and use Data Validation to create your drop-down list.
  2. 2. Access the Developer Tools: Go to the 'Developer' tab on the ribbon and click 'VBA Editor' to access the coding environment.
  3. 3. Add Your Macro: Insert your Worksheet_Change code into the corresponding sheet module, then save your file as a Macro-Enabled Workbook (.xlsm) to preserve the automation.
Fully compatible with Microsoft Excel (.xlsm) macro filesBuilt-in VBA editor for seamless script writing and executionFree and lightweight alternative for complex data managementFamiliar user interface ensuring zero learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my VBA code triggering when I change the drop-down list?

This usually happens if macros are disabled or if the code is placed in a standard Module instead of the specific Sheet module. Ensure you right-click the sheet tab, select 'View Code', paste the script there, and check your macro security settings.

Can I unhide all columns if the drop-down list is left blank?

Yes, you can modify the VBA script to include a condition that checks if the target cell value is empty (e.g., If Target.Value = "" Then). If it is empty, you can set the EntireColumn.Hidden property to False for your entire controlled range.

Does this VBA method work in WPS Office?

Yes, WPS Office Spreadsheet supports VBA macros. You can use the exact same Worksheet_Change event code to hide and unhide columns dynamically, provided you are using a version of WPS Office with the VBA module installed.