1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Business Applications' started by titanalive, Feb 9, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. titanalive

    titanalive Thread Starter

    Joined:
    May 20, 2007
    Messages:
    102
    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
     
  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
  3. titanalive

    titanalive Thread Starter

    Joined:
    May 20, 2007
    Messages:
    102
    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.
     
  4. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
    Happy to help :)
     
  5. waki

    waki

    Joined:
    Mar 1, 2010
    Messages:
    4
    thanks guys, it does work..
    but how do you restore it to normal?
    thanks..
     
  6. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
    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.
     
  7. waki

    waki

    Joined:
    Mar 1, 2010
    Messages:
    4
    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?
     
  8. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
    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
     
  9. waki

    waki

    Joined:
    Mar 1, 2010
    Messages:
    4
  10. waki

    waki

    Joined:
    Mar 1, 2010
    Messages:
    4
    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?
     
  11. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/901506