hide/unhide sheet code

chobanne

Active Member
Joined
Jul 3, 2011
Messages
269
Pls guys, can someone help me

I need simple code for sheet1 depend on values in cell A1. If A1 is true then unhide sheet2, if A1 is false then hide sheet 2.

thank you
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Code:
Sub Hide_It()
    If Sheets(1).Range("a1") = "Change this string" Then
        Sheets(2).Visible = False
    Else
        Sheets(2).Visible = True
    End If
End Sub

Change that string to what ever value you want.

This one is actually shorter
Code:
Sub Hide_It()
    Sheets(2).Visible = (Sheets(1).Range("a1") <> "Change this string")
End Sub
 
Last edited:
Upvote 0
Code:
Sub Hide_It()
    If Sheets(1).Range("a1") = "Change this string" Then
        Sheets(2).Visible = False
    Else
        Sheets(2).Visible = True
    End If
End Sub

Change that string to what ever value you want.

This one is actually shorter
Code:
Sub Hide_It()
    Sheets(2).Visible = (Sheets(1).Range("a1") <> "Change this string")
End Sub

Both of this codes dont work for me. maybe because my sheet are named with enter and exit. Value instead change that string must be with "" or not?
 
Upvote 0
that code means that if a1 on your first sheet (name doesn't matter, only position) says "Change this string", that it will show or hide the 2nd sheet (again, name doesn't matter)
 
Upvote 0
that code means that if a1 on your first sheet (name doesn't matter, only position) says "Change this string", that it will show or hide the 2nd sheet (again, name doesn't matter)

i know that . but those codes dont work for me. sheet 2 (in my case EXIT) cant hide/unhide with this
 
Upvote 0
you know that you have to run that code, right? it doesn't just work. well, unless you put it in a SheetChange event in your sheet1 module.
 
Upvote 0
in the vba editor, open up the sheet1 module, and put this in it
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents= False
    Sheets(2).Visible = (Sheets(1).Range("a1") <> "Change this string")
     Application.EnableEvents= True
End Sub

Before you tell me it doesn't work, tell me what you have on sheet 1 A1. What do you want to hide the sheets with?
 
Last edited:
Upvote 0
in the vba editor, open up the sheet1 module, and put this in it
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents= False
    Sheets(2).Visible = (Sheets(1).Range("a1") <> "Change this string")
     Application.EnableEvents= True
End Sub

Before you tell me it doesn't work, tell me what you have on sheet 1 A1. What do you want to hide the sheets with?

Sheet1 = ENTER
sheet 2 = EXIT
A1 value is true/false
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Sheets(2).Visible = (Sheets(1).Range("a1").Value = True)
    Application.EnableEvents = True
End Sub
It doesn't matter what your sheets are called. If you think they do, then use this instead
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Sheets("EXIT").Visible = (Sheets("ENTER").Range("a1").Value = True)
    Application.EnableEvents = True
End Sub



EDIT: I just realized you wanted the exact opposite of what I posted, so I changed those codes.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top