+ Reply to Thread
Results 1 to 6 of 6

Are you sure message

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-09-2005
    Location
    SC
    Posts
    196

    Are you sure message

    Good Evening!

    I have a simple code that clears a selected area on a worksheet.

    How do add to this code to prompt a message box, "Are you sure you want to clear the cells". Yes will continue on to clear the cells, No would return back to the sheet without clearing the cells.

    Code to clear:

    Sub ClearWorksheetArea()
    Range("A1:I50").Clear
    Range("K1").Select
    End Sub


    Thanks,
    EMoe

  2. #2
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    Sub ClearWorksheetArea()
    Dim t As String
    t = MsgBox("Are you sure you want to clear the cells. ", vbYesNo)
    If t = vbYes Then
    Range("A1:I50").Clear
    Range("K1").Select
    else

    end if
    End Sub

  3. #3
    Norman Jones
    Guest

    Re: Are you sure message

    Hi EMoe,

    Try:

    Sub ClearWorksheetArea()
    If MsgBox("Is there more?", vbYesNo) = vbYes Then
    Range("A1:I50").Clear
    Range("K1").Select
    Else
    'Do something?
    End If
    End Sub


    ---
    Regards,
    Norman



    "EMoe" <EMoe.1qupic_1119146704.6583@excelforum-nospam.com> wrote in message
    news:EMoe.1qupic_1119146704.6583@excelforum-nospam.com...
    >
    > Good Evening!
    >
    > I have a simple code that clears a selected area on a worksheet.
    >
    > How do add to this code to prompt a message box, "Are you sure you want
    > to clear the cells". Yes will continue on to clear the cells, No would
    > return back to the sheet without clearing the cells.
    >
    > Code to clear:
    >
    > Sub ClearWorksheetArea()
    > Range("A1:I50").Clear
    > Range("K1").Select
    > End Sub
    >
    > Thanks,
    > EMoe
    >
    >
    > --
    > EMoe
    > ------------------------------------------------------------------------
    > EMoe's Profile:
    > http://www.excelforum.com/member.php...o&userid=23183
    > View this thread: http://www.excelforum.com/showthread...hreadid=380355
    >




  4. #4
    Norman Jones
    Guest

    Re: Are you sure message

    Hi EMoe,

    That should have been:

    Sub ClearWorksheetArea()
    If MsgBox("Are you sure you want " _
    & "to clear the cells?", _
    vbYesNo) = vbYes Then
    Range("A1:I50").Clear
    Range("K1").Select
    Else
    'Do something?
    End If
    End Sub

    ---
    Regards,
    Norman



    "Norman Jones" <normanjones@whereforartthou.com> wrote in message
    news:OrVAdSHdFHA.2588@TK2MSFTNGP15.phx.gbl...
    > Hi EMoe,
    >
    > Try:
    >
    > Sub ClearWorksheetArea()
    > If MsgBox("Is there more?", vbYesNo) = vbYes Then
    > Range("A1:I50").Clear
    > Range("K1").Select
    > Else
    > 'Do something?
    > End If
    > End Sub
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "EMoe" <EMoe.1qupic_1119146704.6583@excelforum-nospam.com> wrote in
    > message news:EMoe.1qupic_1119146704.6583@excelforum-nospam.com...
    >>
    >> Good Evening!
    >>
    >> I have a simple code that clears a selected area on a worksheet.
    >>
    >> How do add to this code to prompt a message box, "Are you sure you want
    >> to clear the cells". Yes will continue on to clear the cells, No would
    >> return back to the sheet without clearing the cells.
    >>
    >> Code to clear:
    >>
    >> Sub ClearWorksheetArea()
    >> Range("A1:I50").Clear
    >> Range("K1").Select
    >> End Sub
    >>
    >> Thanks,
    >> EMoe
    >>
    >>
    >> --
    >> EMoe
    >> ------------------------------------------------------------------------
    >> EMoe's Profile:
    >> http://www.excelforum.com/member.php...o&userid=23183
    >> View this thread:
    >> http://www.excelforum.com/showthread...hreadid=380355
    >>

    >
    >




  5. #5
    Forum Contributor
    Join Date
    05-09-2005
    Location
    SC
    Posts
    196
    Thanks for everyones input.

    All of the codes provided works.

    Thanks,
    EMoe

  6. #6
    Dave Peterson
    Guest

    Re: Are you sure message

    Sub ClearWorksheetArea()
    dim Resp as long

    resp = msgbox(Prompt:="Are you sure you want to clear: " _
    & Range("A1:I50").address(0,0), buttons:=vbyesno)

    if resp = vbyes then
    Range("A1:I50").clear '.clearcontents????
    end if
    End Sub

    EMoe wrote:
    >
    > Good Evening!
    >
    > I have a simple code that clears a selected area on a worksheet.
    >
    > How do add to this code to prompt a message box, "Are you sure you want
    > to clear the cells". Yes will continue on to clear the cells, No would
    > return back to the sheet without clearing the cells.
    >
    > Code to clear:
    >
    > Sub ClearWorksheetArea()
    > Range("A1:I50").Clear
    > Range("K1").Select
    > End Sub
    >
    > Thanks,
    > EMoe
    >
    > --
    > EMoe
    > ------------------------------------------------------------------------
    > EMoe's Profile: http://www.excelforum.com/member.php...o&userid=23183
    > View this thread: http://www.excelforum.com/showthread...hreadid=380355


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1