VBA - Lock Sheet, but allow certain cells to be edited

Jameo

Active Member
Joined
Apr 14, 2011
Messages
270
Good afternoon all, hope this post finds you well.

I've been looking through various posts regarding the protection of worksheets and cells via vba, and have managed to confuse myself slightly.

I have a sheet ("ControlPage") that I wish to protect, but allow macros to run and edit the sheet. I understand that I would have to use the UserInterFaceOnly:=True optional statement for this.

However, my issue comes when I wish to allow the user to access and change certain cell ranges on the same sheet. In my case this would be cells:

B24, B25, C24, C25, J23, J24, J25, J26

Can anyone give me an idea of how to combine the two please? Also, is there anyway to protect the formatting of those cells? i.e. as you know, if a user was to copy/paste values from a different cell, the destination cell would loose its modified formatting. I could easilly write a short macro to reformat the cell correctly, but just wondered if there is a cleaner method to accomplish this?

Thanks in advance all.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try like this

Code:
Range("B24,B25,C24,C25,J23,J24,J25,J26").Locked = False
ActiveSheet.Protect password:="pw", UserInterfaceOnly:=True
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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