Forum Discussion
Cyndie_Birdsong
Mar 28, 2021Copper Contributor
Having issue with Activesheet.Unprotect allowing all VBA code to run.
I have some macros on a sheet that is protected as it's set up like a user form, which I have protected so it doesn't get messed up by the various users. I've unlocked the cells they can modify, and ...
PeterBartholomew1
Mar 28, 2021Silver Contributor
I believe HansVogelaar has provided the solution to your problem, but you might like to take a further step beyond macro recorder. Unless it is important to you to transfer the font colour, size, cell colour, conditional formats, protection etc., you could simply transfer the values (or, I think in this case, the formula)
'Unprotect the worksheet
ActiveSheet.Unprotect
'Copy formulas
Range("G5:AC21") = Range("AR5").FormulaR1C1
' Protect the sheet again
ActiveSheet.Protect AllowFormattingCells:=True
Personally, I would also use defined Names, just in case you wish to extend the Range "G5:AC21" or someone moves the cell "AR5". It is very easy to forget to adjust the VBA otherwise.
Cyndie_Birdsong
Mar 28, 2021Copper Contributor
And the AR5 cell is behind protection so they can't move it. The main reason I want to protect the sheet is so users can't move anything, only fill in unlocked cells. thanks..