Changing the value of a protected cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Sub go()
Dim goal As Range
Set goal = Sheets("sheet1").Range("A1")

Range("A1") = goal + 1
End Sub

I get an error because this is on a protected sheet and protected cell. How
can I get result without having to unprotect the sheet?
 
You must either unlock the cell prior to protecting it, or unprotect
the sheet, change value, and then protect again. There is no other way
around it, or there would be no point to protecting it. If it is a
cell that I dont mind users editing, I unlock it, otherwise I do the
unprotect, change, protect method.
 
Shawn,
Look at the arguments for the Protect method.
You have an option of UIOnly (or something like that). That means that the
user cannot change the sheet, but code can.

NickHK
 
Assuming you don't want to unlock the cell before you protect the sheet, then

Sub go()
Dim goal As Range
Set goal = Sheets("sheet1").Range("A1")
ActiveSheet.Unprotect Password:="ABC"
Range("A1") = goal + 1
Activesheet.Protect Password:="ABC"
End Sub
 
Dave,
Thanks.
I'm currently on a Chinese system without Office installed, so it was
guesswork.

NickHK
 
Wow!

You live in interesting times.

(not meant as a Chinese curse!)
Dave,
Thanks.
I'm currently on a Chinese system without Office installed, so it was
guesswork.

NickHK
 
I have decided to use sort of a back door method. I am going to make that
cell a formula equal to a value in another sheet that is unprotected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top