Disable cut, copy and paste in range of cell

aashish83

Board Regular
Joined
Feb 15, 2022
Messages
62
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have multiple sheets which already have certain macros running and want to ensure that a range of cells (for e.g. A33:B261) cannot be copied or cut ? i cannot use sheet protection as a method as that interrupts the functioning of existing macros...i am currently manging it with below code but this enables the data to be cut/copy and pasted in a new work book.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Locked = True Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
How about using sheet protection but unprotect before running code and protect the sheet back when done.
You can also protect the sheet user interface only (Sheet1.Protect , , , , UserInterfaceOnly:=True) thus allowing code to edit the sheet with no restrictions
 
Upvote 0
How about using sheet protection but unprotect before running code and protect the sheet back when done.
You can also protect the sheet user interface only (Sheet1.Protect , , , , UserInterfaceOnly:=True) thus allowing code to edit the sheet with no restrictions
Where do i put this code?
 
Upvote 0
In the ThisWorkbook module

VBA Code:
Private Sub Workbook_Open()

    Dim oSh As Worksheet
   
    For Each oSh In Me.Worksheets
        oSh.Protect , , , , True
    Next oSh

End Sub

The above code will prevent users to edit the worksheets via the user interface but will allow code without restrictions.
 
Upvote 0
In the ThisWorkbook module

VBA Code:
Private Sub Workbook_Open()

    Dim oSh As Worksheet
  
    For Each oSh In Me.Worksheets
        oSh.Protect , , , , True
    Next oSh

End Sub

The above code will prevent users to edit the worksheets via the user interface but will allow code without restrictions.
Hi i need the people to be able to edit some part of the worksheet (for e.g. A33:B261) needs to be restricted only for edit or cut copy?
 
Upvote 0
In the ThisWorkbook module

VBA Code:
Private Sub Workbook_Open()

    Dim oSh As Worksheet
  
    For Each oSh In Me.Worksheets
        oSh.Protect , , , , True
    Next oSh

End Sub

The above code will prevent users to edit the worksheets via the user interface but will allow code without restrictions.
is it possible to mark a range to it? for e.g. C6:C19 and A33:A261 only? the rest can be editable?
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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