Ask Your Question
3

How can I hide specific columns that have been given names using a dropdown option on the same sheet?

asked 2021-12-24 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-10-16 17:00:00 +0000

qstack gravatar image

To hide specific columns that have been given names using a dropdown option on the same sheet, you can use the following steps:

  1. Create a dropdown list using data validation in a cell where the user will choose which columns to hide.

  2. Next, assign each column you want to hide with a unique name using the Name Manager. To do this, go to Formulas > Name Manager, click New, give the name a unique name, and select the cell range that represents the column.

  3. Now, create a VBA macro that will detect the dropdown list selection and hide the corresponding named column. To do this, go to Developer > Visual Basic and paste the following code into a new module:

Sub Hide_Column()
Dim selected_column As String
selected_column = Range("dropdown_cell").Value
Range(selected_column).EntireColumn.Hidden = True
End Sub
  1. Replace "dropdown_cell" with the cell reference of the dropdown list you created in step 1.

  2. Save the macro and go back to the sheet with the dropdown list. Assign the macro to the list by right-clicking on the list and selecting "Assign Macro" in the dropdown menu.

  3. Test the macro by selecting an option from the dropdown list. The corresponding column should be hidden.

Note: To unhide a hidden column, simply select the column(s) on either side of the hidden column and right-click to access the context menu, then select "Unhide."

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-12-24 11:00:00 +0000

Seen: 9 times

Last updated: Oct 16 '21