Cut and Paste restriction in certain cells

Grappledog

New Member
Joined
Jul 7, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
The below post I saw from years ago; I was wondering if anyone can assist. I am not at an advanced level when using excel.


I have a spreadsheet that considerable time has been put in to developing, both in content and format.
I have found most people are lazy (imagine that..) and simply cut and paste data. This causes problems in both formulas and formatting.

Is there an easy way to disable (and then re-enable when updates need to be made by the owners) the cut and paste functions?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Here is a way to disable using VBA
Code applies to all except (owner) Grappledog

Put all 3 procedures in ThisWorkbook code module and save the workbook as macro enabled
- code is ignored if placed in either a standard module (like Module1) or in a Sheet Module

VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Application.UserName = "Grappledog" Then Exit Sub
    Dim last As String
    last = Application.CommandBars("Standard").Controls("&Undo").List(1)
    On Error Resume Next
    If Left(last, 5) = "Paste" Then UndoIt
    If Left(last, 9) = "Auto Fill" Then UndoIt
    On Error GoTo 0
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    If Application.UserName = "Grappledog" Then Exit Sub
    Application.CutCopyMode = False
    Debug.Print Application.UserName
    Debug.Print Environ("Username")
End Sub
Private Sub UndoIt()
    With Application
        On Error Resume Next
        .EnableEvents = False
        .Undo
        .EnableEvents = True
        On Error GoTo 0
    End With
End Sub

To use windows user name
VBA Code:
   If Environ("Username") = "Grappledog" Then Exit Sub
 
Upvote 0
Thank you Yongle, I appreciate your response. By chance, is there an easier version for me to follow as the instructions are above my Excel skill set.

Thanks,
G
 
Upvote 0
Have a go - use a copy of your workbook

1. Close all other Excel workbooks
2. Open the one where the code is to be placed
3. {ALT} {F11} takes you to VBA editor
4. Paste the code as instructed


AltF11 2.jpg


5. Amend the code to match your Excel user name, which can be found under File\Options

ApplicationUserName.jpg



6. {ALT} {F11} takes you to back to Excel

7. Save workbook under a different name as macro enabled


Job done
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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