L
lance-news
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
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