# Solved: Disable the cut function in excel to prevent users from messing up formulas !



## titanalive (May 20, 2007)

Hi,

I had to create an excel file for my workplace which is to be accessed by many users and this excel file relies on formulas for quite a bit of calculations that need to be done internally.

Now the problem with excel is that if a user cuts pastes data in any referenced cell, the formula referenceing to that cell tends to throw a #REF error, so thus to prevent users from causing this error I pasted the following code in the ThisWorkbook module of VBA : 

Option Explicit
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)

Select Case Application.CutCopyMode
Case Is = False
'do nothing
Case Is = xlCopy
'do nothing
Case Is = xlCut
MsgBox "Please DO NOT Cut and Paste. Use Copy and Paste; then delete the source."
Application.CutCopyMode = False 'clear clipboard and cancel cut
End Select

End Sub

Private Sub Workbook_Activate()
Application.CellDragAndDrop = False
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CellDragAndDrop = True
End Sub

Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
End Sub

Private Sub Workbook_Open()
Application.CellDragAndDrop = False
End Sub

Now while the above code achieved the intended goal it created another problem in the form that sometimes when users have to copy data into the workbook from another workbook, the data does not get copied as the paste option remains disabled. (PS. The copy and paste works for the workbook internally).

I dont know what I am doing wrong or what is missing in the above code, but any help in this would be great.

Thanks


----------



## Keebellah (Mar 27, 2008)

Take a look at this site (link)

http://www.vbaexpress.com/kb/getarticle.php?kb_id=373

It has serveral examples.

Happy coding


----------



## titanalive (May 20, 2007)

Thanks for the above link Keebelah. It really helped me crack another code I was stuck with.

Anyway as far as the code above was concerned (code in my earlier post) the solution to that too turned out to be simple.

The reason why copy was gettin disabled was due to the cell drag property being disabled.
Just using the first half of the code i.e.

Option Explicit
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)

Select Case Application.CutCopyMode
Case Is = False
'do nothing
Case Is = xlCopy
'do nothing
Case Is = xlCut
MsgBox "Please DO NOT Cut and Paste. Use Copy and Paste; then delete the source."
Application.CutCopyMode = False 'clear clipboard and cancel cut
End Select

End Sub

Fulfills the need to block any cut fuction used in the workbook.


----------



## Keebellah (Mar 27, 2008)

Happy to help


----------



## waki (Mar 1, 2010)

thanks guys, it does work..
but how do you restore it to normal? 
thanks..


----------



## Keebellah (Mar 27, 2008)

reverse the codes.
You hav a macro diabling, wel copy the macro, rename it i.e. Back2Normal and set the values you set to false to true and v.v.


----------



## waki (Mar 1, 2010)

thanks man, i will try that, btw, do you know how to digitally sign the above macro?coz every time I open this workbook, Excel warns me about my own macro and offers to Enable/ Disable macro execution. How can I get around this nuisance?


----------



## Keebellah (Mar 27, 2008)

If you're not on a public network and it's your own PC you may set your macro security level to low.
If you're working with Office 2007 you add secure locations, which would be a harddrive drive folder of your choice and all the excel sheets from that folder will be considered secure.
I use a vbs script for my files that overrides any security setting


----------



## waki (Mar 1, 2010)

i found a solution moments ago, is a seld-signed certficate safe enough? the solution here is pretty simple http://office.microsoft.com/en-us/help/HA012317811033.aspx#1 
thanks..


----------



## waki (Mar 1, 2010)

i have another problem.. it seems like its not possible to highlight, or change font Color on a cell that is unlocked but from a protected sheet.. do you guys know of any solution?


----------

