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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

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,118,812
Messages
5,574,456
Members
412,595
Latest member
slim313
Top