Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I am looking for a way to unload UserForms. I can unload one, but need all others to unload if vbYes is selected: Code used is: Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then Unload UserForm5 End If End Sub UserForm1 is selected prior to UserForm5 as sort is an option on UF5 Any help gratefully received Many Thanks Craig |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I assume you meant if vbOK is selected since the MsgBox has vbOKCancel.
Give this a try. Post back if there is a problem. Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = 1 To UserForms.Count Unload UserForm(i) Next End If End Sub "Craig" wrote in message ... Hi, I am looking for a way to unload UserForms. I can unload one, but need all others to unload if vbYes is selected: Code used is: Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then Unload UserForm5 End If End Sub UserForm1 is selected prior to UserForm5 as sort is an option on UF5 Any help gratefully received Many Thanks Craig |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Might work better this way.
Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = UserForms.Count To 1 Step -1 Unload UserForm(i) Next End If End Sub "Craig" wrote in message ... Hi, I am looking for a way to unload UserForms. I can unload one, but need all others to unload if vbYes is selected: Code used is: Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then Unload UserForm5 End If End Sub UserForm1 is selected prior to UserForm5 as sort is an option on UF5 Any help gratefully received Many Thanks Craig |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am having one of those nights:
Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = UserForms.Count To 1 Step -1 Unload UserForms(i) Next End If This corrects the syntax for a collection item. "Craig" wrote in message ... Hi, I am looking for a way to unload UserForms. I can unload one, but need all others to unload if vbYes is selected: Code used is: Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then Unload UserForm5 End If End Sub UserForm1 is selected prior to UserForm5 as sort is an option on UF5 Any help gratefully received Many Thanks Craig |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My apologies for tardiness....had 'man flu' only just recovered.......
am getting error at: Unload UserForms(i) point in code that you posted Any ideas? Craig "JLGWhiz" wrote: I am having one of those nights: Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = UserForms.Count To 1 Step -1 Unload UserForms(i) Next End If This corrects the syntax for a collection item. "Craig" wrote in message ... Hi, I am looking for a way to unload UserForms. I can unload one, but need all others to unload if vbYes is selected: Code used is: Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then Unload UserForm5 End If End Sub UserForm1 is selected prior to UserForm5 as sort is an option on UF5 Any help gratefully received Many Thanks Craig . |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try changing this line:
For i = UserForms.Count To 1 Step -1 To this: For i = UserForms.Couint - 1 To 0 Step = -1 "Craig" wrote in message ... My apologies for tardiness....had 'man flu' only just recovered....... am getting error at: Unload UserForms(i) point in code that you posted Any ideas? Craig "JLGWhiz" wrote: I am having one of those nights: Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = UserForms.Count To 1 Step -1 Unload UserForms(i) Next End If This corrects the syntax for a collection item. "Craig" wrote in message ... Hi, I am looking for a way to unload UserForms. I can unload one, but need all others to unload if vbYes is selected: Code used is: Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then Unload UserForm5 End If End Sub UserForm1 is selected prior to UserForm5 as sort is an option on UF5 Any help gratefully received Many Thanks Craig . |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just a note that your UserForms must be loaded as ShowModal = False for the
code to work. "Craig" wrote in message ... My apologies for tardiness....had 'man flu' only just recovered....... am getting error at: Unload UserForms(i) point in code that you posted Any ideas? Craig "JLGWhiz" wrote: I am having one of those nights: Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = UserForms.Count To 1 Step -1 Unload UserForms(i) Next End If This corrects the syntax for a collection item. "Craig" wrote in message ... Hi, I am looking for a way to unload UserForms. I can unload one, but need all others to unload if vbYes is selected: Code used is: Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then Unload UserForm5 End If End Sub UserForm1 is selected prior to UserForm5 as sort is an option on UF5 Any help gratefully received Many Thanks Craig . |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry, dont get that bit:
To show UF1: Private Sub CommandButton6_Click() UserForm5.Show End Sub Then press button for sort options and code behind that is: Private Sub CommandButton3_Click() Worksheets("Issues").Visible = True Worksheets("Issues").Select Range("A1").Activate Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = UserForms.Count - 1 To 0 Step = -1 Unload UserForms(i) Next End If End Sub Dont understand where to put the Modal bit? Sorry, dont think Man Flu completely gone !! "JLGWhiz" wrote: Just a note that your UserForms must be loaded as ShowModal = False for the code to work. "Craig" wrote in message ... My apologies for tardiness....had 'man flu' only just recovered....... am getting error at: Unload UserForms(i) point in code that you posted Any ideas? Craig "JLGWhiz" wrote: I am having one of those nights: Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = UserForms.Count To 1 Step -1 Unload UserForms(i) Next End If This corrects the syntax for a collection item. "Craig" wrote in message ... Hi, I am looking for a way to unload UserForms. I can unload one, but need all others to unload if vbYes is selected: Code used is: Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then Unload UserForm5 End If End Sub UserForm1 is selected prior to UserForm5 as sort is an option on UF5 Any help gratefully received Many Thanks Craig . . |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Maybe I have misunderstood your original post. I thought that you had more
than one userform opened at once and wanted to know how to unload them in one command. If you only wanted to unload one UserForm then you do not need the For ... Next loop statement, You can just: Unload UserForm5 ' or whaterver name it is To explain the Modal part. The default condition to load a UserForm is Modal. This condition stops all other events except those controlled by the UserForm until the UserForm is unloaded. In this condition, only one UserForm can be loaded at a time. To load more than one UserForm, the UserForm#.Show ShowModal:=False must be used to load the form in what is commonly referred to as a modeless condition. More than one UserForm can be loaded at a time using this method. It was the second method that I had though you were using, but apparently not. My error, I should have asked long ago. "Craig" wrote in message ... Sorry, dont get that bit: To show UF1: Private Sub CommandButton6_Click() UserForm5.Show End Sub Then press button for sort options and code behind that is: Private Sub CommandButton3_Click() Worksheets("Issues").Visible = True Worksheets("Issues").Select Range("A1").Activate Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = UserForms.Count - 1 To 0 Step = -1 Unload UserForms(i) Next End If End Sub Dont understand where to put the Modal bit? Sorry, dont think Man Flu completely gone !! "JLGWhiz" wrote: Just a note that your UserForms must be loaded as ShowModal = False for the code to work. "Craig" wrote in message ... My apologies for tardiness....had 'man flu' only just recovered....... am getting error at: Unload UserForms(i) point in code that you posted Any ideas? Craig "JLGWhiz" wrote: I am having one of those nights: Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then For i = UserForms.Count To 1 Step -1 Unload UserForms(i) Next End If This corrects the syntax for a collection item. "Craig" wrote in message ... Hi, I am looking for a way to unload UserForms. I can unload one, but need all others to unload if vbYes is selected: Code used is: Private Sub CommandButton1_Click() Range("A5:D50", Range("A5:D50").End(xlDown)).sort Range("B50"), xlAscending Dim Res As VbMsgBoxResult Res = MsgBox("This will sort data into Red, Amber & Green", vbOKCancel) If Res = vbOK Then Unload UserForm5 End If End Sub UserForm1 is selected prior to UserForm5 as sort is an option on UF5 Any help gratefully received Many Thanks Craig . . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
unload vs hide userforms | Excel Programming | |||
Getting error with load/unload of UserForms?? | Excel Programming | |||
unload an add-in from an Macro | Excel Programming | |||
Excel Won't Unload... | Excel Programming | |||
Unload Me | Excel Programming |