Forum Discussion
Hiding sheets
I need to create an Excel function to show/hide a sheet, something like this:
IF A=5 hide sheet2
Anyway to do this?
For this, only a VBA solution would be appropriate.
Here are some steps:
Alt+F11 to open the Visual Basic Editor
Locate the worksheet where you want to add 5 in A1 (i n file example ist Sheet1).
Enter the following code:
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$1" Then ' Change A1 to the cell you want to monitor If Target.Value = 5 Then Sheets("Sheet2").Visible = xlSheetHidden ' Replace "Sheet2" with the actual name of the sheet Else Sheets("Sheet2").Visible = xlSheetVisible ' Replace "Sheet2" with the actual name of the sheet End If End If End SubClose the VBA Editor.
Your must use your workbook as a .xlsm file to retain the functionality.
Example file is included.
I hope that I could help you with this.
2 Replies
- NikolinoDEPlatinum Contributor
For this, only a VBA solution would be appropriate.
Here are some steps:
Alt+F11 to open the Visual Basic Editor
Locate the worksheet where you want to add 5 in A1 (i n file example ist Sheet1).
Enter the following code:
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$1" Then ' Change A1 to the cell you want to monitor If Target.Value = 5 Then Sheets("Sheet2").Visible = xlSheetHidden ' Replace "Sheet2" with the actual name of the sheet Else Sheets("Sheet2").Visible = xlSheetVisible ' Replace "Sheet2" with the actual name of the sheet End If End If End SubClose the VBA Editor.
Your must use your workbook as a .xlsm file to retain the functionality.
Example file is included.
I hope that I could help you with this.
- Agus10Copper ContributorThanks NikolinoDE !!!