How to hide or unhide a specific worksheet based on cell value in another sheet?
Are there any methods for us to hide or unhide a specific worksheet tab based on a cell content in another sheet? For example, when I enter the text “Yes” in the cell G1 of Sheet2, I want the Sheet1 to be hidden, and when I enter “No”, the Sheet1 to be displayed at once. How could I solve this problem in Excel?
Hide or unhide a specific worksheet tab based on cell value with VBA code
Hide or unhide a specific worksheet tab based on cell value with VBA code
To hide or unhide a specific worksheet tab based on a cell value in another worksheet, the following VBA code may do you a favor, please do as follows:
1. Go the worksheet which contains the cell value you want to hide another sheet based on.
2. Right click the sheet tab, and select View Code, in the popped out Microsoft Visual Basic for Applications window, please copy and paste the following code into the blank Module window, see screenshot:
VBA code: Hide or hide a worksheet tab based on cell value:
Private Sub Worksheet_Change(ByVal Target As Range)
If [G1] = "Yes" Then
Sheets("Sheet1").Visible = True
Else
Sheets("Sheet1").Visible = False
End If
End Sub
Note: In the above code, G1 and Yes are the cell and cell content that you want to base on, and Sheet1 is the specific sheet that you want to hide or unhide. You can change them to your need.
3. Then save and close this code, when you enter “No” or other text in cell G1, Sheet1 is hidden, but if you enter “Yes” in the cell, Sheet1 is displayed at once, see screenshots:
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!