Susan Smit
Susan Smit

Reputation: 1

Deleting MsgBox and stop macro from running

Please help to delete msgbox after if statement is met with vbYes. The code also has to stop running so that the user can free type after msgbox disappears.

Here is my code:

Response = MsgBox(“Are you sure you want to change this?”,vbYesNo + vbcritical)
If yourAnswer = vbYes 
Then exit sub

Upvotes: 0

Views: 211

Answers (1)

Robert Mearns
Robert Mearns

Reputation: 11996

The user's Yes or No answer is fed into the Response variable.
That variable is what needs to be tested in the If statement.
See the code below as an example.

Option Explicit

Sub Test()

Dim Response As Integer

    Response = MsgBox("Are you sure you want to change this?", vbYesNo + vbCritical, "Change")
    
    If Response = vbYes Then
        Exit Sub
    Else
        MsgBox "OK, going to change stuff", vbCritical, "Changing stuff"
        'Your code to make the change goes here instead of another message box.
    End If

End Sub

Upvotes: 2

Related Questions