Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete is Pressed then Stop


Hi All,

I am looking for a VBA code that if the delete button is pressed on a
particular cell (B1 - B100), on a worksheet, that a code will stop it.

Something like this;
Private Sub Worksheet_*BeforeDelete(*ByVal target As Excel.Range)
msgbox("cell can not be deleted")
end sub


Please Help

Lenny


--
Lenny_821
------------------------------------------------------------------------
Lenny_821's Profile: http://www.excelforum.com/member.php...o&userid=15179
View this thread: http://www.excelforum.com/showthread...hreadid=268122

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete is Pressed then Stop

Right click on the sheet tab and select view code. Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
On Error GoTo ErrHandler
Set rng = Intersect(Range("B1:B100"), Target)
If rng Is Nothing Then Exit Sub
If (rng.Count 1 And Application.CountA(rng) = 0) Or (rng.Count = 1 _
And IsEmpty(rng)) Then
Application.EnableEvents = False
Application.Undo
End If
ErrHandler:
Application.EnableEvents = True
End Sub

Drawback: If a multicell area is selected that overlaps B1:B100 and the
user hits delete, none of the cells will be deleted.

--
Regards,
Tom Ogilvy


"Lenny_821" wrote in message
...

Hi All,

I am looking for a VBA code that if the delete button is pressed on a
particular cell (B1 - B100), on a worksheet, that a code will stop it.

Something like this;
Private Sub Worksheet_*BeforeDelete(*ByVal target As Excel.Range)
msgbox("cell can not be deleted")
end sub


Please Help

Lenny


--
Lenny_821
------------------------------------------------------------------------
Lenny_821's Profile:

http://www.excelforum.com/member.php...o&userid=15179
View this thread: http://www.excelforum.com/showthread...hreadid=268122



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a COMMAND to stop a current process in Excel(Copy/Delete/ Stegra Excel Discussion (Misc queries) 1 January 13th 09 02:52 PM
How to stop a Control Button moving when I delete columns(Excel) CH-DE-FDS APRIL Excel Discussion (Misc queries) 2 October 28th 08 10:08 AM
Delete macro to stop importing data jgranda[_2_] Excel Programming 0 August 5th 04 02:59 PM
Which button was pressed? Adrian[_4_] Excel Programming 7 April 28th 04 04:55 PM
Trapping key pressed in a worksheet John[_35_] Excel Programming 1 February 28th 04 05:46 AM


All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"