• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Code to unhide a Tab and show

I have the following piece of code which shows sheet 4 and hides sheet 2. I need to have sheet 4 hidden when the form loads, how do I change to code below to unhide sheet 4 and show it, whilst still hiding Sheet 2.

Hope this makes sense.

Code:
'Create contract button - quote 1 visible'
Private Sub CommandButton1_Click()
Sheet1.Cells(47, "R") = 1
Sheet1.Visible = xlSheetHidden
Sheet4.Visible = xlSheetVisible
    If Sheet4.Shapes("Text Box 2").Visible = True Then
    Sheet4.Shapes("Text Box 2").Visible = False
    Sheet4.Shapes("Text Box 4").Visible = False
    Else
    Sheet4.Shapes("Text Box 2").Visible = False
    Sheet4.Shapes("Text Box 4").Visible = False
    End If

End Sub
 
Your code isn't actually doing anything to Sheet2 at all. I've explained below what every bit of your code means:

Code:
'Create contract button - quote 1 visible'
Private Sub CommandButton1_Click()

'Is Being used somewhere
Sheet1.Cells(47, "R") = 1

'Hides Sheet1
Sheet1.Visible = xlSheetHidden

'Shows Sheet4
Sheet4.Visible = xlSheetVisible

'If Text Box 2 on Sheet4 is showing then Hide it & Hide Text Box 4 as well
If Sheet4.Shapes("Text Box 2").Visible = True Then
  Sheet4.Shapes("Text Box 2").Visible = False
  Sheet4.Shapes("Text Box 4").Visible = False
Else
'Otherwise Hide it & Hide Text Box 4 as well
  Sheet4.Shapes("Text Box 2").Visible = False
  Sheet4.Shapes("Text Box 4").Visible = False
End If

'So essentially all it does is in Sheet1, CellR47, it writes 1
'Then it hides Sheet1 and Unhides Sheet4
'Then For some reason it uses an IF condition which isn't needed, because in both cases its Hiding Text Box 2 and Text Box 4

End Sub
 
Hi

Thanks for the reply. I should have read my message before I sent it. It should say.

When I open the workbook Sheet 1 is visible and all other sheets are hidden. I have a button on the page. I want this button to Hide sheet 1 and show sheet 4.
 
Your code already does that. Link the code to the button so that when you press it. It will hide Sheet1 (Right click & assign macro). If you want the code to automatically run when you open the workbook then code will need to go in the "ThisWorkbook" part using a Workbook_Open event.

Open.png
 
Back
Top