Results 1 to 3 of 3

Thread: VBA Code To Ask User With Yes No Cancel Message Box Before Protecting Cells

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12

    VBA Code To Ask User With Yes No Cancel Message Box Before Protecting Cells

    First,how do i add a Yes ,No and Cancel button to the message box in the commandbutton_1 code?

    I want the messagebox to be clicked on either Yes,No or Cancelled before the action of clearcontents is activated

    Thanks

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.eileenslounge.com/viewtopic.php?f=44&t=40455&p=313035#p313035
    https://www.eileenslounge.com/viewtopic.php?f=18&t=40411&p=312889#p312889
    https://www.eileenslounge.com/viewtopic.php?f=18&t=40411&p=312886#p312886
    https://www.eileenslounge.com/viewtopic.php?f=18&t=40411&p=312752#p312752
    https://www.eileenslounge.com/viewtopic.php?f=18&t=40411&p=312734#p312734
    https://www.eileenslounge.com/viewtopic.php?f=18&t=40411&p=312727#p312727
    https://www.eileenslounge.com/viewtopic.php?f=18&t=40411&p=312724#p312724
    https://www.eileenslounge.com/viewtopic.php?f=44&t=40374&p=312535#p312535
    https://www.eileenslounge.com/viewtopic.php?p=312533#p312533
    https://www.eileenslounge.com/viewtopic.php?f=44&t=40373&p=312499#p312499
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg. 9xhyRrsUUOM9xpn-GDkL3o
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=UgzlC5LBazG6SMDP4nl4AaABAg
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=UgzlC5LBazG6SMDP4nl4AaABAg. 9zYoeePv8sZ9zYqog9KZ5B
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg. 9xhyRrsUUOM9zYlZPKdOpm
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Attached Files Attached Files
    Last edited by DocAElstein; 03-01-2024 at 03:03 PM.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Yes / No is understood. But what will the cancelled option do?

    Anyway, a very simple way to do this is

    Code:
    Private Sub CommandButton1_Click()
        
        If vbYes = MsgBox("Are you sure you want to delete", vbYesNo + vbQuestion, "Clear Cell Contents") Then
            Range("F7:L13,F18:L24,F29:L35").ClearContents
        End If
    
    
    End Sub

    But a more elaborate one which can be used to different actions based on response

    Code:
    Private Sub CommandButton1_Click()
    
        Dim vblResponse As VbMsgBoxResult
        
        vblResponse = MsgBox("Are you sure you want to delete", vbYesNoCancel + vbQuestion, "Clear Cell Contents")
        If vblResponse = vbYes Then
            Range("F7:L13,F18:L24,F29:L35").ClearContents
        ElseIf vblResponse = vbNo Then
            'Code here if user clicked no
        ElseIf vblResponse = vbCancel Then
            'Code here if user clicked cancel
        End If
    
    
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    Thank you

Similar Threads

  1. Replies: 8
    Last Post: 08-17-2013, 02:42 PM
  2. VBA code message box added
    By rich_cirillo in forum Excel Help
    Replies: 6
    Last Post: 07-08-2013, 05:19 PM
  3. Replies: 8
    Last Post: 05-21-2013, 06:34 AM
  4. Display sheet names in a message box
    By pells in forum Excel Help
    Replies: 4
    Last Post: 02-13-2013, 07:33 PM
  5. Message Box Before Saving Document
    By Lucero in forum Excel Help
    Replies: 2
    Last Post: 04-15-2012, 07:09 AM

Posting Permissions

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