Run Macro from command button in userform - display msgbox at the end of the macro

theprincipal78

Board Regular
Joined
Aug 5, 2009
Messages
68
hi all

I have a userform with a command button which fires a macro.

everything works fine so far.

my problem is:
I would like to add a msgbox at the end of the macro which confirmes "successfully completed".


I cannnot simply add the msgbox at the end of the macro. don't know what I'm doing wrong.
(see below)


Private Sub CommandButtonOK_Click()

If Me.OptionButton1.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "Government Securities"
ElseIf Me.OptionButton2.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "Corporate Bonds"
ElseIf Me.OptionButton3.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "Mortgage Market Instruments"
ElseIf Me.OptionButton4.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "Money Market Securities"
ElseIf Me.OptionButton5.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "U.S. Municipal Bonds"
ElseIf Me.OptionButton6.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "Preferred Securities"
ElseIf Me.OptionButton7.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "Equities"
ElseIf Me.OptionButton8.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "Commodities"
ElseIf Me.OptionButton9.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "Indices"
ElseIf Me.OptionButton10.Value = True Then
ThisWorkbook.Worksheets("PropertyWorksheet").Range("A1").Value = "Foreign Currency"
End If


Unload Me

Application.ScreenUpdating = False
Sheets("MySheet1").Select

Application.ScreenUpdating = False
'run macro
MyMacro1 (adds, hides and deletes various sheets)
MyMacro2

Application.ScreenUpdating = False
Sheets("MySheet1").Select
Range("A1").Select

'MsgBox "Successfully completed!"

End Sub

appreciate the help!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try changing all this:
Rich (BB code):
Unload Me


Application.ScreenUpdating = False
Sheets("MySheet1").Select


Application.ScreenUpdating = False
'run macro
MyMacro1 (adds, hides and deletes various sheets)
MyMacro2


Application.ScreenUpdating = False
Sheets("MySheet1").Select
Range("A1").Select


'MsgBox "Successfully completed!"

to:
Rich (BB code):
   Application.ScreenUpdating = False
      'run macro
      MyMacro1
      MyMacro2
   Application.ScreenUpdating = True
   
    
   MsgBox "Successfully completed!"
Unload Me
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top