Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Prevent deleting multiple cells at once

How can I prevent a user from deleting more than one cell at a time? I have
code that returns the cell's original contents if a user presses delete, but
if they highlight several cells and press delete, it doesn't work (the cells'
contents are actually deleted). I added a message box to the code as below,
but it doesn't actually prevent them from deleting the cells' contents.

If Target.Cells.Count 1 Then
MsgBox("You can only edit one cell at a time.")
Exit Sub
End If

Thanks,
~ Horatio

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,090
Default Prevent deleting multiple cells at once

Horatio
What you have to do is to first determine if Target.Count1.
If it is, issue an Undo command like:
Application.EnableEvents=False
Application.Undo
Application.EnableEvents=True
This gets your values back. Now you can display the message box. The
complete macro would look like:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
MsgBox "Whatever"
End If
End Sub
"Horatio J. Bilge, Jr." wrote in
message ...
How can I prevent a user from deleting more than one cell at a time? I
have
code that returns the cell's original contents if a user presses delete,
but
if they highlight several cells and press delete, it doesn't work (the
cells'
contents are actually deleted). I added a message box to the code as
below,
but it doesn't actually prevent them from deleting the cells' contents.

If Target.Cells.Count 1 Then
MsgBox("You can only edit one cell at a time.")
Exit Sub
End If

Thanks,
~ Horatio



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Prevent deleting multiple cells at once

Thanks. That works great.


"Otto Moehrbach" wrote:

Horatio
What you have to do is to first determine if Target.Count1.
If it is, issue an Undo command like:
Application.EnableEvents=False
Application.Undo
Application.EnableEvents=True
This gets your values back. Now you can display the message box. The
complete macro would look like:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
MsgBox "Whatever"
End If
End Sub
"Horatio J. Bilge, Jr." wrote in
message ...
How can I prevent a user from deleting more than one cell at a time? I
have
code that returns the cell's original contents if a user presses delete,
but
if they highlight several cells and press delete, it doesn't work (the
cells'
contents are actually deleted). I added a message box to the code as
below,
but it doesn't actually prevent them from deleting the cells' contents.

If Target.Cells.Count 1 Then
MsgBox("You can only edit one cell at a time.")
Exit Sub
End If

Thanks,
~ Horatio




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
protect cells in excel to prevent users from deleting formulae locking cells in excel Excel Discussion (Misc queries) 2 June 14th 06 05:56 PM
How can I prevent someone from deleting a shared workbook? Brian Excel Worksheet Functions 2 May 19th 06 02:49 PM
How to prevent Excel from deleting leading zeros? ljCharlie Excel Discussion (Misc queries) 1 October 31st 05 10:04 PM
how prevent formula in cell from deleting when deleting value???? sh-boom New Users to Excel 1 September 30th 05 06:12 PM
How do I prevent someone from deleting a workbook? JSP Excel Discussion (Misc queries) 5 September 5th 05 04:51 PM


All times are GMT +1. The time now is 05:08 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"