Hide sheets not working from User Form

Rafiki_Runner

New Member
Joined
Apr 25, 2018
Messages
3
Hi - new to this and pretty useless with code, so hoping somebody can help.
I have a 'Dashboard' with multiple tabs for different uses.
I had in my Welcome tab a drop down with 2 options for a submission type.
when I select Unitised, it hides the Time & Materials tab as I don't need this one.
If I select Time & Materials, it hides the Unitised tab.

all was good.

Then, I tried to get clever and added user forms to my dashboard. It made it look much more slick and user friendly.
however, now when I select the submission type, the other tab doesn't hide.
I have tried a couple of different things and found that I can get it to hide when I submit the form, but as soon as I close the form, the sheet comes back.

The code I am using is:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If [B15] = "Time & Materials" Then
Sheets("Summary (Unitised)").Visible = False
Else
Sheets("Summary (Unitised)").Visible = True
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If [B15] = "Unitised" Then
Sheets("Summary (T&M)").Visible = False
Else
Sheets("Summary (T&M)").Visible = True
End If
End Sub

I tried to copy the contents of cell B15 to a cell in one of these worksheets and run the code from there in case it was just because I was using a User Form and thus wasn't physically changing the cell myself. This seemed to work well, however I had to click into that worksheet before it would recognize the selection change and then hide it.
Is there a way I can run this without needing to use SelectionChange? (told you I was useless at coding, there is probably a very simple solution - I hope!) But I have been looking at loads of examples/forums and all show SelectionChange to achieve the hide worksheet based on a cell value.

Thanks,

Luke
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Why don't you run your code straight from your userform?

Add a command button to it and put your code into there so when the user selects the submission they want, they click the command button and run the code you want. Personally, I'd prefer that than a change event.
 
Upvote 0
Thanks BenGee, I have multiple text boxes and drop downs in the user form and it even jumps from one user form to another to capture financial information.
I have to admit that I didn't think to try doing this and it makes perfect sense to do it this way! This morning I attempted this using radio buttons, tried it with radio buttons and the code into the submit command buttons (on both the first user form and the second), then tried again with command buttons for each submission type, but to no avail. I basically just put the same code I posted above into these controls, but even when I could get the sheets to hide when submitting the user form, as soon as I closed the user form, the sheets just come back.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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