Hide sheets

deanl33069

Board Regular
Joined
May 2, 2019
Messages
120
I have a workbook with 4 sheets and a form.
when i launch my workbook I have the form in front with 3 buttons to open the different sheets.
Ont the sheets I have a button to bring you back to the form..looks like this.

Sub openform()
JFSmainsheet.Show False


End Sub
I would like to have the worksheets be minimized or hidden when this macro is run.
hope this make ssense.

tyvm

Dean
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this

In the events of thisworkbook, enter the following code

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Sheets("Sheet1").Visible = 0
    Sheets("Sheet2").Visible = 0
    Sheets("Sheet3").Visible = 0
    ActiveWorkbook.Save
End Sub


Private Sub Workbook_Open()
    JFSmainsheet.Show
End Sub


In your userform

Code:
Private Sub CommandButton1_Click()
    Call HideSheets
    Sheets("Sheet1").Visible = -1
    Sheets("Sheet1").Select
End Sub


Private Sub CommandButton2_Click()
    Call HideSheets
    Sheets("Sheet2").Visible = -1
    Sheets("Sheet2").Select
End Sub


Private Sub CommandButton3_Click()
    Call HideSheets
    Sheets("Sheet3").Visible = -1
    Sheets("Sheet3").Select
End Sub


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Sheets("Main").Visible = -1
    Call HideSheets
End Sub


Sub HideSheets()
    Sheets("Sheet1").Visible = 0
    Sheets("Sheet2").Visible = 0
    Sheets("Sheet3").Visible = 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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