Forum Discussion
rbalza
Jul 29, 2021Brass Contributor
Lock cells with VBA script
Hi everyone, could someone help me out on this one please. So I have locked specific cells (highlighted on the pic). However, there were an existing script beside it (with red formatted column) which...
rbalza
Aug 01, 2021Brass Contributor
Hi, doesn't seem to work. Would you mind sharing how it works, please? Thanks!
Subodh_Tiwari_sktneer
Aug 01, 2021Silver Contributor
- rbalzaAug 01, 2021Brass Contributor
Subodh_Tiwari_sktneer
Appreciated the time that you are taking on this. How can I lock an un-contiguous range? ie. C14:C20, C22:C23, C25:C26, and any other ranges per se? Thanks much!- Subodh_Tiwari_sktneerAug 01, 2021Silver Contributor
You may try something like this...
Dim rng As Range Set rng = Range("C14:C20, C22:C23, C25:C26") ActiveSheet.Unprotect 'Unprotect the sheet before you change the lock property along with the password if any rng.Locked = True ActiveSheet.Protect 'Protect the sheet again in the end- rbalzaAug 01, 2021Brass Contributor
Not sure what I have missed but there's an error to it. Error says "unable to set the Locked property of the Range class". Thanks!