![]() |
Form Button with 3 Userforms Help
I have a command button that runs this macro when pressed:
Sub UserForm_Initialize() Application.ScreenUpdating = False MsgBox ("Please select the Grouping variable") UserForm1.Show UserForm1.Hide MsgBox ("Please select the variables you wish to see Means for") UserForm2.Show UserForm2.Hide MsgBox ("Please select the variables you wish to see Percentages for") UserForm3.Show UserForm3.Hide End Sub The problem is that the USERFORM1 does not hide before the MSGBOX and USERFORM2 open and USERFORM2 does not hide before the MSGBOX and USERFORM3 open. What do I need to add to this macro or to the USERFORM code so that a USERFORM closes before the next one opens? Lance Here is the code for Userform1. Userform2 and Userform3 are similar. Columns on CommandButton?_Click are all that change. Private Sub UserForm_Initialize() Dim rListSort As Range, rOldList As Range Dim strRowSource As String 'Parse the address of the sorted unique items strRowSource = Sheet2.Name & "!" & Sheet2.Range _ ("A2", Sheet2.Range("A65536").End(xlUp)).Address With UserForm1.ListBox1 'Parse new one .RowSource = strRowSource End With End Sub Private Sub CommandButton1_Click() Sheets("Vars").Range("E2:E2").Clear For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) Then Sheets("Vars").Range("E2").Value = ListBox1.List(i) End If Next Sheets("Vars").Select Columns("E:E").Select Selection.Interior.ColorIndex = 6 Cells(1, 1).Select Sheets("MainSheet").Select UserForm1.Hide End Sub Private Sub CommandButton2_Click() UserForm1.Hide End Sub Private Sub UserForm_Terminate() UserForm1.Hide End Sub |
Form Button with 3 Userforms Help
This code should be in a general module.
Sub Button1_Click() Application.ScreenUpdating = False MsgBox ("Please select the Grouping variable") UserForm1.Show DoEvents MsgBox ("Please select the variables you wish to see Means for") UserForm2.Show DoEvents MsgBox ("Please select the variables you wish to see Percentages for") UserForm3.Show DoEvents Unload Userform3 Unload Userform2 Unload Userform1 End Sub Get rid of your terminate events. -- Regards, Tom Ogilvy wrote in message ... I have a command button that runs this macro when pressed: Sub UserForm_Initialize() Application.ScreenUpdating = False MsgBox ("Please select the Grouping variable") UserForm1.Show UserForm1.Hide MsgBox ("Please select the variables you wish to see Means for") UserForm2.Show UserForm2.Hide MsgBox ("Please select the variables you wish to see Percentages for") UserForm3.Show UserForm3.Hide End Sub The problem is that the USERFORM1 does not hide before the MSGBOX and USERFORM2 open and USERFORM2 does not hide before the MSGBOX and USERFORM3 open. What do I need to add to this macro or to the USERFORM code so that a USERFORM closes before the next one opens? Lance Here is the code for Userform1. Userform2 and Userform3 are similar. Columns on CommandButton?_Click are all that change. Private Sub UserForm_Initialize() Dim rListSort As Range, rOldList As Range Dim strRowSource As String 'Parse the address of the sorted unique items strRowSource = Sheet2.Name & "!" & Sheet2.Range _ ("A2", Sheet2.Range("A65536").End(xlUp)).Address With UserForm1.ListBox1 'Parse new one .RowSource = strRowSource End With End Sub Private Sub CommandButton1_Click() Sheets("Vars").Range("E2:E2").Clear For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) Then Sheets("Vars").Range("E2").Value = ListBox1.List(i) End If Next Sheets("Vars").Select Columns("E:E").Select Selection.Interior.ColorIndex = 6 Cells(1, 1).Select Sheets("MainSheet").Select UserForm1.Hide End Sub Private Sub CommandButton2_Click() UserForm1.Hide End Sub Private Sub UserForm_Terminate() UserForm1.Hide End Sub |
Form Button with 3 Userforms Help
The below code works but
Application.ScreenUpdating must be set to TRUE. Lance Tom Ogilvy wrote: This code should be in a general module. Sub Button1_Click() Application.ScreenUpdating = False MsgBox ("Please select the Grouping variable") UserForm1.Show DoEvents MsgBox ("Please select the variables you wish to see Means for") UserForm2.Show DoEvents MsgBox ("Please select the variables you wish to see Percentages for") UserForm3.Show DoEvents Unload Userform3 Unload Userform2 Unload Userform1 End Sub Get rid of your terminate events. |
Form Button with 3 Userforms Help
I didn't even notice you had screenupdating set to false. Yes, if I had
noticed that I would have recommended setting it to true. Regards, Tom Ogilvy wrote in message ... The below code works but Application.ScreenUpdating must be set to TRUE. Lance Tom Ogilvy wrote: This code should be in a general module. Sub Button1_Click() Application.ScreenUpdating = False MsgBox ("Please select the Grouping variable") UserForm1.Show DoEvents MsgBox ("Please select the variables you wish to see Means for") UserForm2.Show DoEvents MsgBox ("Please select the variables you wish to see Percentages for") UserForm3.Show DoEvents Unload Userform3 Unload Userform2 Unload Userform1 End Sub Get rid of your terminate events. |
All times are GMT +1. The time now is 10:34 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com