I have 1 workbook that contains 3 worksheets. On load i want to set the 2 worksheets hidden, then on set these visible on certain mouse or keyboard events.
Sub HideSheet()
Worksheets("Sheet2".Visible = False
Worksheets("Sheet3".Visible = False
End Sub
Sub ShowSheet()
Worksheets("Sheet2".Visible = True
Worksheets("Sheet3".Visible = True
End Sub
For those who don't know how to place a shortcut key
1 Open Excel.
2 Right click on the Sheet name tab.
3 Select View Code from the Pop-up menu
4 Insert a New Module
5 Copy the code and paste it
6 Push Alt+Q to return to Excels normal view.
7 Push Alt+F8 and then select the macro name
8 Push Options and assign a shortcut key.
There are 3 states to the Visible worksheet property
xlSheetVisible
xlSheetHidden
xlSheetVeryHidden
The first 2 can be manipulated by the user from menu selection. The latter can ONLY be changed via VBA or in the VB Editor.
In this instance, Subscript out of range usually indicates a non-existant worksheet name. Make sure that your 2 macros are either in a MODULE or in the WorkBook Object.
Are you sure your worksheet is named "sheet1"? There is no other reason why your code wouldn't work. You can't hide the all worksheets, but the error message when you try to do that is a different one.
I confess I was referencing the wrong sheet name - my humble apologies, however, I have now corrected this to "Post codes", closed it all down and reopened.
Now I'm getting error 1004 unable to set the visible property of the worksheet class.
My hair is falling out rapidly!
PassingBy
"Happiness is not getting what you want but wanting what you have."
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.