+ Reply to Thread
Results 1 to 2 of 2

Protecting Sheet by accident

  1. #1
    ExcelMonkey
    Guest

    Protecting Sheet by accident

    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

  2. #2
    Rowan Drummond
    Guest

    Re: Protecting Sheet by accident

    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

    ExcelMonkey wrote:
    > 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


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1