PC Review


Reply
Thread Tools Rate Thread

Detect Delete

 
 
Dave
Guest
Posts: n/a
 
      27th Apr 2008
Hi,
I'm trying to write some code that detects whether someone has deleted data
using the delete key, on a particular sheet.
I use the following to catch data in the active cell before it is deleted,
and store it in AB2:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not IsEmpty(ActiveCell) Then Range("AB2") = ActiveCell.Value
End Sub

I don't mind if data is added or changed - I just want to know if it's been
deleted.
The delete-detect macro would display a message box telling the user that
they've been naughty, then use the value of AB2 to reinstate the deleted
data. This part I can do. I just can't seem to get the detect-delete part.

I have tried the following:

Private Sub Worksheet_Change(ByVal Target As Range)
If IsEmpty(ActiveCell) Then MsgBox _
"No manual deletions allowed on this page" _
& Chr(10) & "Use the Delete button in Cell H1"
End Sub

This displays the msgbox when I delete something, but it also displays when
I add data to a cell, then hit enter. Any way of doing what I want?

Any help would be appreciated.
Regards - Dave.


 
Reply With Quote
 
 
 
 
Alex Simmons
Guest
Posts: n/a
 
      27th Apr 2008
On Apr 27, 7:24*pm, Dave <D...@discussions.microsoft.com> wrote:
> Hi,
> I'm trying to write some code that detects whether someone has deleted data
> using the delete key, on a particular sheet.
> I use the following to catch data in the active cell before it is deleted,
> and store it in AB2:
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> If Not IsEmpty(ActiveCell) Then Range("AB2") = ActiveCell.Value
> End Sub
>
> I don't mind if data is added or changed - I just want to know if it's been
> deleted.
> The delete-detect macro would display a message box telling the user that
> they've been naughty, then use the value of AB2 to reinstate the deleted
> data. This part I can do. I just can't seem to get the detect-delete part.
>
> I have tried the following:
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> If IsEmpty(ActiveCell) Then MsgBox _
> "No manual deletions allowed on this page" _
> & Chr(10) & "Use the Delete button in Cell H1"
> End Sub
>
> This displays the msgbox when I delete something, but it also displays when
> I add data to a cell, then hit enter. Any way of doing what I want?
>
> Any help would be appreciated.
> Regards - Dave.


Dave,

You need to change the If IsEmpty(ActiveCell) to If IsEmpty(Target)

Cheers

Alex
 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      28th Apr 2008
Hi Alex,
Thanks a lot! Works a treat
Regards - Dave, Kiwi in Brazil
>
> You need to change the If IsEmpty(ActiveCell) to If IsEmpty(Target)
>
> Cheers
>
> Alex
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detect Delete Column/Row vs Insert Otto Moehrbach Microsoft Excel Programming 0 20th Apr 2006 02:08 PM
detect and delete existing sheet =?Utf-8?B?c3dpZnRjb2Rl?= Microsoft Excel Misc 3 16th Sep 2005 05:20 PM
Can I detect new sms come and read or delete it? c#? Liren Zhao Microsoft Dot NET Compact Framework 1 26th Jun 2005 11:09 AM
detect the spyware and can't delete kakoro Security and Anti-Spyware Community 1 28th Feb 2005 03:55 PM
Re: How to detect an insert/delete? Dave Peterson Microsoft Excel Programming 0 12th Sep 2003 03:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:40 AM.