Message Box upon delete command

rafikarp

New Member
Joined
Dec 23, 2008
Messages
21
Hi,

I am looking for a macro that will load a message box everytime a user of a spreadsheet wants to delete a cell or selection.

Basically, if you try to delete a cell, before the clear contents command is carried out, a message box pops up and asks if you wish to delete the cell or not.

The message box part I have (below) but I need coding before it that will make the emssage box show upon the delete command.

If MsgBox("Are you sure you wish to delete this selection", vbYesNo) = vbYes Then Selection.ClearContents

Any help would be much appreciated. Thanks.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
If you are trying to capture the 'Delete' keypress before it deletes what is in a cell, put the following in a module in VBA:

Code:
Sub TrapDelKey()
Application.OnKey "{DEL}", "MsgBoxProc"
End Sub
 
Sub UnTrapDelKey()
Application.OnKey "{DEL}"
End Sub
 
Sub MsgboxProc()
If MsgBox("Are you sure you wish to delete this selection", vbYesNo) = vbYes Then Selection.ClearContents
End Sub

Run 'TrapDelKey' to turn on the capture of the 'Del' key. Now when you press the 'Del' key your message box will appear.

Run 'UnTrapDelKey' to put the 'Del' key back in normal ops.

Hope this helps.

Owen
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top