Macro asking "Are You Sure?"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have a worksheet that contains several lines of data which I want the user
to be able to clear using a macro, which is easy enough but before the macro
actualy clears all the cells, is it possible to ask the user are they sure ??

any ideas ??

Thanks

Anthony
 
Hi - you could use the this - replace the range A1:B2 with the cells you
want to delete

Sub Test()
Dim rng As Range
Dim var As Variant

Set rng = Range("A1:B2")

var = MsgBox("Are you sure you want to delete the following cells " _
& vbCr & vbCr & rng.Address, vbOKCancel + vbExclamation, _
"Delete Confirmation")

If var = vbOK Then
rng.ClearContents
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top