ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Macro asking "Are You Sure?" (https://www.excelbanter.com/excel-worksheet-functions/12825-macro-asking-%22-you-sure-%22.html)

Anthony

Macro asking "Are You Sure?"
 
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

James

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

"Anthony" wrote in message
...
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




Anthony

James,

Thanks, that works great !!

"Anthony" wrote:

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



All times are GMT +1. The time now is 04:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com