Forum Discussion
Hide columns upon opening a file?
Hi!
I have an excel workbook that I use all the time to track information. Other colleagues also consult this workbook, but only want to see information in some columns. The other columns are for me to manage, but sometimes I leave them all unhidden at the end of the day and close out the workbook. Is there any way to have the columns hidden automatically when the file is opened even if I left them unhidden when I closed it?
Thanks!
- Haytham AmairahSilver Contributor
Hi,
This needs to an advanced solution by using a VBA event handler.
Please follow these steps:
- Press Alt+F11 to open the VBA editor
- From the Project - VBAProject in the left-hand side, double-click ThisWorkbook
- Copy the below code into ThisWorkbook code module
Sub Workbook_Open()
Sheets("Sheet1").Columns("C:F").Hidden = True
End Sub- Save the workbook as (.xlsm) file extension
The above code is just an example, and it will hide the columns C through F in Sheet 1 each time you open the workbook.
If these columns are already hidden when you open the workbook, the code will leave them as they are.
Hope that helps