Disable cut, copy and paste in range of cell

aashish83

Board Regular
Joined
Feb 15, 2022
Messages
61
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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,001
Office Version
  1. 2016
Platform
  1. Windows
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
 

aashish83

Board Regular
Joined
Feb 15, 2022
Messages
61
Office Version
  1. 365
Platform
  1. Windows
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?
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,001
Office Version
  1. 2016
Platform
  1. Windows
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.
 

aashish83

Board Regular
Joined
Feb 15, 2022
Messages
61
Office Version
  1. 365
Platform
  1. Windows
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?
 

aashish83

Board Regular
Joined
Feb 15, 2022
Messages
61
Office Version
  1. 365
Platform
  1. Windows
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?
 

Forum statistics

Threads
1,181,956
Messages
5,932,953
Members
436,869
Latest member
ABGTH

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
Top