Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick Excel VBA syntax question

Status
Not open for further replies.

westma

Technical User
Jul 16, 2003
74
US
Hello, I am trying to change the value in a cell only if the worksheet is protected, but I can't seem to find the correct syntax. The code is as follows

Code:
If [Worksheet g is not protected] Then
    g.Cells(1, 3).Value = 1
End If

I don't want excel to attempt to write the value in the locked cell when the sheet is protected and cause an error.

Thanks
 
Have a look at the Worksheet.ProtectionMode property and the Worksheet.Protection object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 



Hi,

Depending on the logic for your sheet, you may want to turn protection OFF before your code runs, and then turn it ON.

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top