• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Ask A Question Before Run A Macro

hoomantt

Member
please help me to write a code that if some one clicks on trash icon in my excel attached file that clear some ranges in some worksheets , first open a window to ask from user that are you really want to delete all these data?
then if user click on "yes" button then run macro and if user click on "NO" button, that macro do not work and close the Ask window.
 

Attachments

  • TEST2.xlsb
    54.8 KB · Views: 0
Your question is asked twice in this forum. Following answer provided to both postings :

Code:
Option Explicit

Sub DataChanes()
  Dim Msg As String, Title As String
  Dim Config As Integer, Ans As Integer
  Msg = "Are You Sure ?"
  Msg = Msg & vbNewLine & vbNewLine
  Msg = Msg & "Changes Cannot Be Undone."
 
    Title = "Delete Data ?"
    Config = vbYesNo + vbExclamation
    Ans = MsgBox(Msg, Config, Title)
        If Ans = vbYes Then Hoomantt
        If Ans = vbNo Then Exit Sub
End Sub




Sub Hoomantt()
    Sheets("USA").Range("A3:C5").Clear
    Sheets("Italy").Range("A2:B4").Clear
    Sheets("CHINA").Range("A5:C9").Clear
End Sub
 
Your question is asked twice in this forum. Following answer provided to both postings :

Code:
Option Explicit

Sub DataChanes()
  Dim Msg As String, Title As String
  Dim Config As Integer, Ans As Integer
  Msg = "Are You Sure ?"
  Msg = Msg & vbNewLine & vbNewLine
  Msg = Msg & "Changes Cannot Be Undone."

    Title = "Delete Data ?"
    Config = vbYesNo + vbExclamation
    Ans = MsgBox(Msg, Config, Title)
        If Ans = vbYes Then Hoomantt
        If Ans = vbNo Then Exit Sub
End Sub




Sub Hoomantt()
    Sheets("USA").Range("A3:C5").Clear
    Sheets("Italy").Range("A2:B4").Clear
    Sheets("CHINA").Range("A5:C9").Clear
End Sub

Thanks a lot
 
Back
Top