Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default 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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button on Form to Add more rows SaM Excel Worksheet Functions 1 May 24th 10 10:05 PM
Form button - 2007 oldLearner57 Excel Discussion (Misc queries) 4 August 11th 07 01:46 PM
Form button Thor Excel Discussion (Misc queries) 1 May 5th 07 09:37 PM
Button to create a new form ihatetheredskins Excel Worksheet Functions 1 May 3rd 07 07:43 PM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 06:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"