Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004

    Talking Unanswered: What is the code to prompt user before action is taken

    Good afternoon,

    I have a small bit that I need help with. I am using Excel 2003 and have a small bit of code to Clear out all of my entries on my sheet for me and it works well. However, I would like to actually Prompt the user as to whether or not they are wanting to perform that action BEFORE they wipe out the data on the sheet. Here is what I have to clear it, but not sure how to prompt them and where to place it.

    [code]
    Sub Clear()
    '
    ' 8-25-05 by "Bud" to clear all contents
    ' for new input.
    '
    ' Keyboard Shortcut: Ctrl+c
    '
    Range("A2:Q65").Select
    Selection.ClearContents
    Range("A3").Select
    End Sub
    [code/]

    Thanks very much and have a nice one,
    Bud

  2. #2
    Join Date
    Mar 2009
    Location
    Worthing, UK
    Posts
    16
    Please find the code below... I hope it will work
    Code:
    Sub Clear()
    '
    
    'by Muhammad Anisur Rahman
    
    
    
    If MsgBox("Are you sure", vbYesNo, "Confirm") = vbYes Then
    
    'Your Code here
    
    Range("A2:Q65").ClearContents
    
    Range("A3").Select
    
    MsgBox "All data cleared" ' You can delete this MsgBox if not required
    
    
    End If
    '
    
    End Sub

  3. #3
    Join Date
    Feb 2009
    Posts
    6
    use following code instead
    Code:
    '
    ' 8-25-05 by "Bud" to clear all contents
    ' for new input.
    '
    ' Keyboard Shortcut: Ctrl+c
    '
    If MsgBox("Do you want to clear the contents", vbYesNo) = vbYes Then
    Range("A2:Q65").Select
    Selection.ClearContents
    Range("A3").Select
    
    End If

  4. #4
    Join Date
    Mar 2009
    Location
    Worthing, UK
    Posts
    16
    Hi

    I think I already gave the code... and mine is not recorded Macro .. and you can clear contents without selecting a Range.. its faster.

    Regrds

    Quote Originally Posted by Chris Bode
    use following code instead
    Code:
    '
    ' 8-25-05 by "Bud" to clear all contents
    ' for new input.
    '
    ' Keyboard Shortcut: Ctrl+c
    '
    If MsgBox("Do you want to clear the contents", vbYesNo) = vbYes Then
    Range("A2:Q65").Select
    Selection.ClearContents
    Range("A3").Select
    
    End If

Posting Permissions

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