View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default Unload UserForms

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