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


arrow blue right bubble 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

doc hide tab based on cell value 1

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:

doc hide tab based on cell value 2
 1
doc hide tab based on cell value 3

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    walidorafrafi@gmail.com · 1 years ago
    Hello
    Thank you for the tip. I need to do the same scenario but not on one cell only (G1 in this case) but on all cells of column G. I have tried with "Range" but it didn't work.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("X2:X100") = "" Then
    Sheets("EU TASK BASED MEASUREMENTS").Visible = False
    Else
    Sheets("EU TASK BASED MEASUREMENTS").Visible = True
    End If
    End Sub


    Thank you in advance
    • To post as a guest, your comment is unpublished.
      Scott Hobin · 1 years ago
      Any chance this was answered? I am also running into this scenario where a whole range comes into play instead of just one cell... I used this same coding with the same results.