How do I protect a number of sheets allowing the user to add a com

P

Prashanth KR

Hi,

How do I protect a workbook having a number of sheets (around 50) allowing
the user to add a comment. I tried this with the following macro:

Sub Protect()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Protect Password:="Protect"
Next ws
End Sub

But it would not allow me to add a "Comment" in the unprotected cells.
Kindly help me to create a macro so that I can protect all sheets at one shot
and also allow users to add comments in the unprotected cells.

Please also note that Iam very new to VBA.

Your help is much appreciated,
Prashanth KR
 
G

Gary''s Student

For a SINGLE sheet that is unProtected:

Sub Macro1()
With ActiveSheet
.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True
.EnableSelection = xlUnlockedCells
End With
End Sub

will:
1. Protect the sheet
2. allow unlocked cells to receive comments
3. not allow locked cells to receive comments

Insert in a loop
 
G

Gord Dibben

Sub Protect()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
With ws
.Protect Password:="Protect", DrawingObjects:=False, Contents:=True
.EnableSelection = xlUnlockedCells
End With
Next ws
End Sub


Gord Dibben MS Excel MVP
 
P

Prashanth KR

Hello Gary,

It was really very helpful. Thanks again. Hope to be in touch with you.

My appreciations for the immediate response.

Prashanth KR.
 
P

Prashanth KR

Wow.... this worked wonderful. And this is what I was looking at. Thanks a
lot Gord. Iam totally impressed and saved me a lot of time as I had more than
50 sheets.

My appreciations for your immediate response.
Prashanth KR.
 
P

Prashanth KR

Wow Gord .... this is what I was looking for. It worked perfectly.

Thanks again,

My sincere appreciations for your immediate response.
Prashanth KR.
 

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

Top