ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Hide or display worksheets based on form (https://www.excelbanter.com/excel-discussion-misc-queries/215062-hide-display-worksheets-based-form.html)

Shawnn

Hide or display worksheets based on form
 
Worksheet 1 displays a list of questions. Based on the answer of those
questions (via checkbox), I would like to display different worksheets. For
example the worksheet one is always displayed. If you select yes to question
#1, then worksheet 2 appears. If you select yes to question #2 then
worksheet 3 also appears. Can this be done?

Simon Lloyd[_59_]

Hide or display worksheets based on form
 

Yes of course it can be done, using code similar to below, it goes in
the sheet1 code module:

Code:
--------------------
Private Sub CheckBox1_Click()
Dim Sh As Worksheet
For Each Sh In Sheets
If Sh.Name = "Sheet1" Or Sh.Name = "Sheet2" Then
Else
Sh.Visible = xlSheetHidden
End If
End Sub
Private Sub CheckBox2_Click()
Dim Sh As Worksheet
For Each Sh In Sheets
If Sh.Name = "Sheet1" Or Sh.Name = "Sheet3" Then
Else
Sh.Visible = xlSheetHidden
End If
End Sub
Private Sub CheckBox3_Click()
Dim Sh As Worksheet
For Each Sh In Sheets
If Sh.Name = "Sheet1" Or Sh.Name = "Sheet4" Then
Else
Sh.Visible = xlSheetHidden
End If
End Sub
--------------------
Shawnn;164128 Wrote:
Worksheet 1 displays a list of questions. Based on the answer of those
questions (via checkbox), I would like to display different worksheets.
For
example the worksheet one is always displayed. If you select yes to
question
#1, then worksheet 2 appears. If you select yes to question #2 then
worksheet 3 also appears. Can this be done?



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=45581


Shane Devenshire[_2_]

Hide or display worksheets based on form
 
Hi,

Assuming you have a separate checkbox for each sheet the code for each would
look something like this

Private Sub CheckBox1_Click()
If CheckBox1 = True Then
Sheet2.Visible = xlSheetVisible
Else
Sheet2.Visible = xlSheetHidden
End If
End Sub

--
If this helps, please click the Yes button

Cheers,
Shane Devenshire


"Shawnn" wrote:

Worksheet 1 displays a list of questions. Based on the answer of those
questions (via checkbox), I would like to display different worksheets. For
example the worksheet one is always displayed. If you select yes to question
#1, then worksheet 2 appears. If you select yes to question #2 then
worksheet 3 also appears. Can this be done?


Shane Devenshire[_2_]

Hide or display worksheets based on form
 
Hi again,

I realize I should add that in the notation

Sheet2.Visible = xlSheetVisible

Sheet2 is the code windows name for the sheet if you use the spreadsheet
name you must write the above line as

Sheets("Sheet2").Visible = xlSheetVisible

--
If this helps, please click the Yes button

Cheers,
Shane Devenshire


"Shawnn" wrote:

Worksheet 1 displays a list of questions. Based on the answer of those
questions (via checkbox), I would like to display different worksheets. For
example the worksheet one is always displayed. If you select yes to question
#1, then worksheet 2 appears. If you select yes to question #2 then
worksheet 3 also appears. Can this be done?



All times are GMT +1. The time now is 10:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com