Lock cell range VBA

Solved
flag -  
eriiic Posted messages 24581 Registration date   Status Contributor Last intervention   -
Hello,

I have an Excel workbook that I need to send to colleagues. I have a data sheet in which I want to lock the range (A1:F2). Then I want to leave the range (G1:J2) for my colleagues to fill in their information in those cells.

They will then need to return the file to me.

I tried this:

Sub LockCells() Sheets("OUTIL").Select Range("A1:F2").Select selection.Locked = True selection.FormulaHidden = False ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True Range("A1").Select end sub 

It doesn't work because the sheet protection prevents me from writing in the cells.

Can you help me?

Thank you in advance!

Configuration: Windows / Chrome 66.0.3359.139

2 answers

flag
 
I found my answer after several trial and error!

Sub LockTestTest() Sheets("TOOL").Select Range("A1:F2").Select selection.Locked = True Range("G1:J2").Select selection.Locked = False selection.FormulaHidden = False ActiveSheet.Protect [/contents/64-password Password]:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True Range("A1").Select End Sub
3
eriiic Posted messages 24581 Registration date   Status Contributor Last intervention   7 281
 
Hello,

it's good to have found it.
But this can be done manually, the macro is unnecessary.
Go to Cell format / Protection to (un)lock a selection, then protect the sheet.
eric

--
By continuously trying, we eventually succeed.
So the more it fails, the more chances we have that it works. (the Shadoks)
In addition to the thank you (yes, yes, it happens!!!), remember to mark it as resolved. Thank you.
0