If cell is deleted, can this initiate an action?

RobertBon

New Member
Joined
Sep 27, 2011
Messages
27
Hello,

Is there a function in vba that will perform an action, once a specific cell (or range of cells) is deleted. So: "if cell "whatever" is deleted, than perform "this" action"

In the worksheet_change I've already tried:
If target.value = "" Then;
If target.value = vbNullString Then;

but I feel they're not the best options, are there any other methods?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Take a look at Intersect


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Set isect = Intersect(Range(Target.Address), Range("B7"))
If Not isect Is Nothing Then
    'a/k/a how to annoy   
    Application.EnableEvents = False
    Application.Undo
    Range("B7") = "Can't get rid of me!!!"
    Application.EnableEvents = True
End If
End Sub
 
Last edited:
Upvote 0
I'm using intersect in my code already. I didn't try that "address" method though. What does Range(target.address) mean? And why do you have application.undo

curious.
 
Upvote 0
What does Range(target.address) mean?
It means I don't get a type-mismatch error on using just 'Target'.

And why do you have application.undo
demonstration purposes
If the user tries to change/clear contents/delete the value of a cell that I don't want them to, I change it back.
[One can delete/insert a row/column to move the 'protected' cell out of this rule; but that too can be locked; and most don't care to hose the functionality of the workbook anyway.]
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,513
Members
452,921
Latest member
BBQKING

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