简体   繁体   中英

Protect cells in excel but should be able to copy them

If I use this code to protect a worksheet, how can I make it so that the user still can copy the cells? And can you specify certain cells that should NOT be protected, or at least the user should be able to edit them?

Worksheets("EKONOMI").Protect UserInterfaceOnly:=True

You can define if user is allowed to select cells in protected sheet by using

Worksheets("EKONOMI").EnableSelection = xlNoRestrictions 'worksheet has to be protected for this to take effect

To make user able to edit certain cells you have to unlock the cells before the protection. For instance you can use the following to make Range C3 as unlocked cell

ActiveSheet.Range("C3").Select
Selection.Locked = False

Sheets("EKONOMI").Activate ActiveSheet.Unprotect Password:="123" 'ActiveSheet.Protection.AllowEditRanges(1).Delete ActiveSheet.Protection.AllowEditRanges.Add Title:="Range1", Range:=Range("A1:A10") ActiveSheet.Protect Password:="123"

Please find the above code to protect sheet by allowing user to edit patricular range of cells.

 ActiveSheet.Protection.AllowEditRanges.Add Title:="Range1", Range:=Range("A1:A10") 

Mention the range name and range size for the user to edit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM