Results 1 to 8 of 8

Thread: "Are You Sure?" Prompt on "Clear All" Button Press

  1. #1
    Board Regular
    Join Date
    Oct 2016
    Posts
    123
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default "Are You Sure?" Prompt on "Clear All" Button Press

    Hello,

    I would like Excel to prompt the user with this question, "Are You Sure" when selecting the 'Clear All' button on my form. Here's what my code looks like now:

    Macros Name =
    ClearYNH

    Sub ClearYNH()
    '
    ' ClearYNH Macro
    '
    '
    Range("BW9:BW20,BV9:BV20,BU9:BU20,BT9:BT20,BS9:BS20,BR9:BR20").Select
    Range("BR9").Activate
    Selection.ClearContents
    Range("BR9").Select


    End Sub

  2. #2
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    2,783
    Post Thanks / Like
    Mentioned
    36 Post(s)
    Tagged
    1 Thread(s)

    Default Re: "Are You Sure?" Prompt on "Clear All" Button Press

    Code:
    Sub ClearYNH()
    Dim answer As Variant
    
    
      answer = MsgBox("Are you sure ?", vbYesNo + vbQuestion, "Really ?")
      
        If answer = vbYes Then
            Range("BW9:BW20,BV9:BV20,BU9:BU20,BT9:BT20,BS9:BS20,BR9:BR20").Select
            Range("BR9").Activate
            Selection.ClearContents
            Range("BR9").Select
    
    
        Else
            Exit Sub
        End If
    
    
    End Sub

  3. #3
    MrExcel MVP shg's Avatar
    Join Date
    May 2008
    Location
    The Great State of Texas
    Posts
    21,607
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    14 Thread(s)

    Default Re: "Are You Sure?" Prompt on "Clear All" Button Press

    Code:
    Sub ClearYNH()
      If MsgBox("Are you SURE?", vbYesNo) = vbYes Then Range("BR2:BR9, BS9:BW20").ClearContents
    End Sub

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    27,963
    Post Thanks / Like
    Mentioned
    467 Post(s)
    Tagged
    47 Thread(s)

    Default Re: "Are You Sure?" Prompt on "Clear All" Button Press

    Try
    Code:
    Sub ClearYNH()
    '
    ' ClearYNH Macro
    '
    If MsgBox("Are you sure you want to clear the form?", vbYesNo) = vbNo Then Exit Sub
    Range("BW9:BW20,BV9:BV20,BU9:BU20,BT9:BT20,BS9:BS20,BR9:BR20").ClearContents
    Range("BR9").Select
    
    
    End Sub
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  5. #5
    Board Regular
    Join Date
    Oct 2016
    Posts
    123
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: "Are You Sure?" Prompt on "Clear All" Button Press

    Hello Fluff,

    Thank you very much! This worked out like a charm!

  6. #6
    Board Regular
    Join Date
    Oct 2016
    Posts
    123
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: "Are You Sure?" Prompt on "Clear All" Button Press

    Hello Logit,

    Thank you for your assistance.

  7. #7
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    2,783
    Post Thanks / Like
    Mentioned
    36 Post(s)
    Tagged
    1 Thread(s)

    Default Re: "Are You Sure?" Prompt on "Clear All" Button Press

    .
    You are welcome. Glad to help.

  8. #8
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    27,963
    Post Thanks / Like
    Mentioned
    467 Post(s)
    Tagged
    47 Thread(s)

    Default Re: "Are You Sure?" Prompt on "Clear All" Button Press

    You're welcome & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •