Userforms keep stacking up on top of each other

Nogslaw

Well-known Member
Joined
Jul 9, 2004
Messages
904
I am trying to teach myself about userforms now. The problem I have is that when I move from one to another, the first one doesn't hide like I think it should. The second one just piles on top of it. It is pretty simple code, nothing fancy. Am I not understanding something correctly? Here is a sample of my code.

Code:
Private Sub OptionButton2_Click()
'Option to Edit Associate List
Switchboard_Form.OptionButton2.Value = False
Switchboard_Form.Hide
Application.ScreenUpdating = False
With Sheets("Assoc List")
.Visible = xlSheetVisible
.Activate
End With
Assoc_List.Show
Sheets("Assoc List").Visible = xlSheetHidden
Application.ScreenUpdating = True
End Sub

Also, I tried putting a stop in the code before turning off the screen updating, to see if anything was different. When I did that, the first form disappeared, and after I pressed play again, the 2nd form was the only one visible. Without stopping though, both forms are visible on the screen. Any suggestions?
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Moving the second ScreenUpdating statement up worked for me:

Code:
Private Sub OptionButton2_Click()
'  Option to Edit Associate List
   Switchboard_Form.OptionButton2.Value = False
   Switchboard_Form.Hide
   Application.ScreenUpdating = False
   With Sheets("Assoc List")
      .Visible = xlSheetVisible
      .Activate
   End With
   Application.ScreenUpdating = True
   Assoc_List.Show
   Sheets("Assoc List").Visible = xlSheetHidden
End Sub

If it's after the Show statement it won't run until the UserForm is dismissed.
 

Nogslaw

Well-known Member
Joined
Jul 9, 2004
Messages
904
Thanks Andrew. That did work. It just seems out of sequence to me that the hide command comes before the screenupdating is turned off, and yet the form does not get hidden. Anyway, thanks for the help.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,354
Messages
5,595,674
Members
414,008
Latest member
zcaa0g

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
Top