EXCEL MsgBox Confirmation of Macro Execution

Solved
Hello!

Here's my question:
I have a macro that deletes rows, and I have put an execution button on my sheet.
(So far, so good.)

Now I would like to create a confirmation message to confirm executing the macro if someone clicks on this button.
While searching a bit, I found this macro:

Sub MyFunction()
If MsgBox("Irreversible operation. Do you wish to continue?", vbQuestion + vbYesNo, "QUESTION ...") = vbYes Then
...
...
...
Else
...
End If
...
End Sub

But I can't apply it to mine (the ..... don't help me).

Thank you for your help.

Laptitepero

5 answers

  1. Hello,

    The error is here:

    If vbCancel Then Exit Sub Else End If


    It should be:
    If yourmsgbox = vbCancel Then Exit Sub End If


    ;o)
    “What one conceives well is clearly expressed, and the words to say it come easily.”
    Nicolas Boileau
    1. My God, it's so good when it works! A thousand times thank you!
      Have a nice day!
  2. Hello everyone,
    I have exactly the same problem as lapetitepero, but your information is not helping me.
    My syntax is as follows:
     yourmsgbox = MsgBox("Are you sure you validate?", vbOKCancel, "confirmation") If vbCancel Then Exit Sub Else End If 


    Then my code to execute if you click on Ok is located here.
    In this case, whether I click on Ok or Cancel, it's the cancel case that executes. But where is the error?
    1. For those interested, here is the response:
      'Msgbox Ok + Cancel yourmsgbox = MsgBox("Are you sure to validate?", vbOKCancel, "Confirmation") If yourmsgbox = vbCancel Then Exit Sub End If
  3. Hello,

    The "little dots" are the code that must be executed, that is to say your code.

    Sub MyFunction() If MsgBox("Irreversible operation. Do you want to continue?", vbQuestion + vbYesNo, "QUESTION ...") = vbYes Then ' YOUR CODE IF THE ANSWER IS "YES" Else ' YOUR CODE IF THE ANSWER IS "NO" End If End Sub 


    ;o)
    --
    “What is well conceived is clearly said, And the words to say it come easily.”
    Nicolas Boileau
    1. Oki, and to say not to do anything if the answer is no,
      is there a special code?

      Also, for the part in () after MsgBox, what can I change?
      "QUESTION....", I put my question back "Irreversible operation...?"

      Thank you.
    2. Well, there's no special code!!! If there's nothing to do, there's nothing to code... so you can remove the Else. Or you can put an Exit Sub in the Else to exit the procedure.

      In MsgBox, "QUESTION..." is the title that will appear in the blue bar of the dialog box. You can put whatever you want.
    3. Great thank you, it's honestly perfect!!!!!
  4. If it can help you,
    here is my basic macro:

    Sub SuppLigne() Dim Lig As Long Sheets("Modèle").Select Lig = ActiveCell.Row Rows(Lig).Delete Sheets("Résultat").Rows(Lig).Delete Sheets("Constantes").Rows(Lig).Delete End Sub
    1. Yahoo, everything is working great!
      Thank you very much!
      1. Content for you :o)

        Good luck and take care.

        ;o)