Forum

How do I add a feat...
 
Notifications
Clear all

How do I add a feature to unhide tabs

10 Posts
3 Users
0 Reactions
52 Views
(@gfaz)
Posts: 27
Eminent Member
Topic starter
 

Hi

I'd like to be able to be able to unhide tabs when the user selects an option. What is the best way to handle this?

Thanks

John

 
Posted : 20/03/2020 6:33 pm
(@purfleet)
Posts: 412
Reputable Member
 

Something like this should work - needs to be in the main tab module.

You can get a bit more creative with the hiding if you have a lot of sheets - for example have another sub that hides all worksheets by default then unhide the one you want at each case, in that way each case willl only be 2 lines

Personally i tend to prefer actual buttons rather than selecting a cell as i think the worksheet is doing less work - the button performs a specific task rather than a selection change which runs each time a cell is selected

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Debug.Print Target

Select Case Target

Case ""

Worksheets("Option 1").Visible = xlHidden
Worksheets("Option 2").Visible = xlHidden
Worksheets("Option 3").Visible = xlHidden

Case "Option 1"

Worksheets("Option 1").Visible = True
Worksheets("Option 2").Visible = xlHidden
Worksheets("Option 3").Visible = xlHidden

Case "Option 2"

Worksheets("Option 1").Visible = xlHidden
Worksheets("Option 2").Visible = True
Worksheets("Option 3").Visible = xlHidden

Case "Option 3"

Worksheets("Option 1").Visible = xlHidden
Worksheets("Option 2").Visible = xlHidden
Worksheets("Option 3").Visible = True
End Select

End Sub

Purfleet

 
Posted : 21/03/2020 1:02 am
(@gfaz)
Posts: 27
Eminent Member
Topic starter
 

Thanks Purfleet,

I'd like to use the buttons as well.  How would you go about it?

Thanks

 
Posted : 21/03/2020 10:18 am
(@purfleet)
Posts: 412
Reputable Member
 

Just create a sub for each button with simular code then assign each sub to a button

Sub Option1()

Worksheets("Option 1").Visible = True
Worksheets("Option 2").Visible = xlHidden
Worksheets("Option 3").Visible = xlHidden

End Sub

Sub Option2()

Worksheets("Option 1").Visible = xlHidden
Worksheets("Option 2").Visible = True
Worksheets("Option 3").Visible = xlHidden

End Sub

Sub Option3()r

Worksheets("Option 1").Visible = xlHidden
Worksheets("Option 2").Visible = xlHidden
Worksheets("Option 3").Visible = True

End Sub

 
Posted : 21/03/2020 10:28 am
(@gfaz)
Posts: 27
Eminent Member
Topic starter
 

Here is the current layout of my file (see attached)

 
Posted : 21/03/2020 12:48 pm
(@gfaz)
Posts: 27
Eminent Member
Topic starter
 

I haven't had success.  Please see my file.

Thanks for your guidance.

 
Posted : 21/03/2020 6:47 pm
(@purfleet)
Posts: 412
Reputable Member
 

Morning John

What triggers the sheets to be unhidden? is it the check boxes on the bidder profile?

I have been looking around the form and noted a couple of things

The Private Sub Worksheet_SelectionChange(ByVal Target As Range) was erroring as you had a space after the 3_Thessalon_Bid_Schedule_058 worksheet name

The Subs you created for each worksheet began with a number which VBA doesnt like

I have added buttons to your form (they can be tidied up later) and changed the 3 Subs so that the first one opens Thessalon & La Cloche, the second one opens just parry and the third opens all.

Hopefully this give you some guidance - let me know you get on or if you need anything else

Purfleet

 
Posted : 22/03/2020 1:38 am
(@gfaz)
Posts: 27
Eminent Member
Topic starter
 

Good Morning Purfleet,

This is very helpful.

I greatly appreciate your guidance.

 

Thank you!

John

 
Posted : 22/03/2020 7:42 am
(@gfaz)
Posts: 27
Eminent Member
Topic starter
 

Hi Purfleet,

I just noticed that after I select an option and I begin filling in the fields on the main Bidder Profile tab that the select tabs hide and I have to go and re-select.

How do I stop that from occurring?

Thanks in advance for your help.

John

 
Posted : 22/03/2020 8:38 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi John,

The Worksheet_SelectionChange was still executing when you selected cells on the Bidder Profile sheet.  This was causing sheets to be hidden as you moved around cells.

I've entered an Exit Sub statement at the top of the sub to prevent the code being run.  I didn't delete the Sub in case you decided you needed it.  So if you don't need it then you can delete the sub.

Regards

Phil

 
Posted : 27/03/2020 8:56 pm
Share: