Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-12-2017, 10:54 PM
ArviLaanemets ArviLaanemets is offline msgbox when deleting cells Windows 8 msgbox when deleting cells Office 2016
Expert
 
Join Date: May 2017
Posts: 949
ArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant future
Default

Quote:
Originally Posted by NoSparks View Post
If the message box is a must, you need the normal means of deleting the cell contents to initiate it.



As ArviLaanemets says, the Change event firing every time something changes will slow down your worksheet
but depending on the worksheet that may or may not be an issue.

Put this code into the sheet module and give it a try.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
    Dim aCell As Range
 
For Each aCell In Target.Cells
    If aCell.Value = "" Then
        If MsgBox("Are you sure you want to " & _
          "delete cell contents ?", 36, "DELETE CELLS ?") <> vbYes Then
              Application.EnableEvents = False
              Application.Undo
              Application.EnableEvents = True
        End If
    End If
    Exit For
Next aCell
 
End Sub
Hi!

As I stressed, the change event is fired after you move to another cell! So p.e. you selected cell A2 and cleared cell contents. So long as you don't leave the cell, nothing happens. Then you pressed Tab key - the cursor moves to B2. When this cell is empty, your script undoes last change - which was moving to B2

Probably the only way will be saving at end of your scrip the current selected range to global variable, and at start of scrip (in your For . . Next cycle) you chek the range saved after previous change. And then you need 2 undo's whenever this range is empty and you want to undo deletion.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
msgbox when deleting cells Trigger Beep or MsgBox when key combo accidentally pressed NotQuiteANovice Word VBA 1 04-07-2017 05:41 PM
msgbox when deleting cells Deleting rows based on the text in certain cells VBA ThisGuyJohn Excel Programming 5 02-03-2017 03:16 PM
msgbox when deleting cells On Open MsgBox for use in Template sent out to colleagues to gather information Lancashire Lad Word VBA 2 10-26-2015 10:22 AM
Deleting info from specific table cells jamierbooth Word VBA 3 07-29-2014 03:20 PM
msgbox when deleting cells Make MsgBox appear... Jamtart PowerPoint 3 09-01-2012 08:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft