prevent delete, paste, cut many cells

zico8

Board Regular
Joined
Jul 13, 2015
Messages
227
Hi,

I have one sheet where almost all cells execute some macros by Worksheet_change event.
Therefore I need to prevent all actions where user can change more than one cell at the time.

I am going to use the code:
Code:
Private Sub Worksheet_Change (byVal Target As Range)
If Target.Cells.Count > 1 Then
Application.EnableEvents = False
Application.Undo
Msgbox "Not allowed action !"
Application.EnableEvents = True
Exit Sub
End If
....
....
End Sub

It works (I think so) for attempts of delete as well as paste in many cells at the same time but the problem is when user will cut several cells. The message box appears only when cutted cells are pasted to other. So the Application.Undo works duringe the paste action and the second time when inserting oryginal values in the correct places.
At the end all is messed up.

How can I prevent then?


Is there something else that I did not consider that can brake my idea due to any unexpected user actions?
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this (untested)

Code:
[COLOR=#0101FD][FONT=Consolas]Private[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] [/FONT][/COLOR][COLOR=#0101FD][FONT=Consolas]Sub[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] Worksheet_SelectionChange([/FONT][/COLOR][COLOR=#0101FD][FONT=Consolas]ByVal[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] Target [/FONT][/COLOR][COLOR=#0101FD][FONT=Consolas]As[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] Range)
   Target.Cells(1).Select
End Sub[/FONT][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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