1

I got some help from another member with my question Copy Range and Paste Values in another Sheet's specific Range and so far everything is working great thanks to @simoco but now I'm just thinking I want to add an additional feature to it.

How can I add a message box with the option to "Ok" to run the macro or "Cancel" to not run it?

Since I know it will be most likely be used with duplicate data and I don't know how to stop it from pasting the same data over again, I want to at least warn to double check before running the macro or to run it if sure.

Thanks in advance.

Community
  • 1
  • 1
BlueSun3k1
  • 757
  • 5
  • 21
  • 39

1 Answers1

1

Try this one:

Sub test()
    If MsgBox("Run macro?", vbOKCancel + vbQuestion, "My Title") = vbCancel Then
        Exit Sub
    End If

    'your code here
End Sub

if user press "Cancel" button, the macro would be terminated.

Dmitry Pavliv
  • 35,333
  • 13
  • 79
  • 80