Protecting Sheet by accident

G

Guest

I have a routine that loops through cells in sheets to find protected cells.
For some reason, if the sheet in question is NOT protected, after running the
code, the sheet IS protected. However I am not sure why this happens. Is
there something here I am doing by accident. Note "Cell" is a Public
Variable. There is more code than this. If the answer is not here, I need
to find a way of trapping the protection of the sheet so that I can see when
this happens.

If CellIsHiddenProtected(Cell) Then
Do something
End If

Public Function CellIsHiddenProtected(rng As Range)
If rng.Parent.Protect = True Then
If rng.Locked = True Or rng.FormulaHidden = True Then
CellIsHiddenProtected = True
End If
End If
End Function

Thanks
 
R

Rowan Drummond

Try changing your function to query the ProtectContents property:

Public Function CellIsHiddenProtected(rng As Range)
If rng.Parent.ProtectContents = True Then
If rng.Locked = True Or rng.FormulaHidden = True Then
CellIsHiddenProtected = True
End If
End If
End Function

Hope this helps
Rowan
 

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