Ant
Ant

Reputation: 3

MS Excel / VB message box with multiple options

I am trying to create a message box in Excel with 3 buttons

I can create the 3 buttons and display the relevant message however I cannot get each button to do a different action

See below coding which I have already started however I know it is incorrect

Do not be too concerned with the actions as I am more concerned with how to get each button to do a separate action

MANY THANKS Ant

Sub Macro1()
'Macro1
If MsgBox( _
Prompt:="Are you sure you want to clear the events from the previous log?    Click YES to confirm or NO to keep events or cancel.", _
Buttons:=vbYesNoCancel) Then If vbYes Then Range("A1") = Range("A1") + 1 'increment hidden sequence num

nosoumission = noclient & Range("A1")
Sheets("Sheet1").Range("G9") = nosoumission
Range("B13").ClearContents
Application.Dialogs(xlDialogSaveAs).Show

If vbNo Then Range("A1") = Range("A1") + 1 'increment hidden sequence num

nosoumission = noclient & Range("A1")
Sheets("Sheet1").Range("G9") = nosoumission
Application.Dialogs(xlDialogSaveAs).Show

If vbCancel Then Exit Sub

End Sub

Upvotes: 0

Views: 8577

Answers (1)

YowE3K
YowE3K

Reputation: 23994

I suspect you are trying to do something like this:

Sub Macro1()
    Select Case MsgBox(Prompt:="Are you sure you want to clear the events from the previous log?    Click YES to confirm or NO to keep events or cancel.", _
                       Buttons:=vbYesNoCancel)
        Case vbYes
            Range("A1") = Range("A1") + 1 'increment hidden sequence num
            nosoumission = noclient & Range("A1")
            Sheets("Sheet1").Range("G9") = nosoumission
            Range("B13").ClearContents
            Application.Dialogs(xlDialogSaveAs).Show
        Case vbNo
            Range("A1") = Range("A1") + 1 'increment hidden sequence num
            nosoumission = noclient & Range("A1")
            Sheets("Sheet1").Range("G9") = nosoumission
            Application.Dialogs(xlDialogSaveAs).Show
        Case vbCancel
            Exit Sub
    End Select
End Sub

Upvotes: 1

Related Questions