VBA to protect cell in excel

Closed
Report
-
Posts
2847
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
January 13, 2022
-
Hello,

Hello,
I need a help if some one can help me.
i a fresh in excel vba code writing. please provide a code to protect a cell with password when the cell value is yes, and if the value is no un protect.
Thanks in advance.

1 reply

Posts
2847
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
January 13, 2022
491
Hi Hemu,

Since you are new to VBA, you should get familiar with the macro recorder.

Start by unblocking all cells except the one cell. The option can be found under the Protection tab of Cell Properties.

Then record a macro > protect and unprotect sheet with password.
Check to see how that looks like.

Use that recorded code together with a logic like:
If range(your cell) = "Yes" then
use the protect sheet part
elseif range(your cell) = "No" then
use the unprotect sheet part
end if

Let us know how it goes.

Best regards,
Trowa
0