Solved: Disable the cut function in excel to prevent users from messing up formulas ! 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
__________________ Titans were not a joke |