Access the protected cell via Macro only

harjas

New member
Joined
Jul 26, 2012
Messages
7
Reaction score
0
Points
0
hi,

I'm on the verge of completing my excel program. At the end I was looking to lock all the cells of the sheet except those which require user inputs. I'm running the program mostly via macros.
The problem is that when I protect the sheet, i'm not able to run the macro. (error: the sheet is protected and therefore read-only)

The following options were selected while protecting the sheet:
1) Protect worksheet and content of locked cells (cannot uncheck this option)
2) select unlocked cells

Please help me to lock the cells and meanwhile execute the macro to change values in the locked cells.

Thanks
 

Bob Phillips

Super Moderator
Staff member
Joined
Mar 21, 2011
Messages
1,940
Reaction score
0
Points
36
Excel Version(s)
O365
Just unprotect the sheet at the start of your macro and protect it again at the end.
 

harjas

New member
Joined
Jul 26, 2012
Messages
7
Reaction score
0
Points
0
After completing the excel program, someone else is going to use it. So, i can't protect and unprotect it each time !

I just want user to select unlocked cells and feed the input. The user should be restricted to change any value in the locked cell. Only background macro should calculate and change the value of the locked cell accordingly.
 

Bob Phillips

Super Moderator
Staff member
Joined
Mar 21, 2011
Messages
1,940
Reaction score
0
Points
36
Excel Version(s)
O365
You can, you do it in the code. I do it all the time.

Code:
Worksheets("name").Unprotect

'your code

Worksheets("name").Protect
 
Top