+ Reply to Thread
Results 1 to 10 of 10

Show if the protection for a worksheet is on or off.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Show if the protection for a worksheet is on or off.

    I'm trying to indicate in cell E1 whether protection for my worksheet is on or off.

    I tried this in CF

    =CELL("protect",E1)=0
    but don't find it responds after protecting / unprotecting the worksheet.

    I wondered is some event VBA could provide some simple text and a change of colour in E1 to show worksheet protection status.

    Can someone suggest some VBA to satisfy this?

    Grateful for any advice.

    Using Excel , Word and Access 2003 - For the whole of 2024

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Show if the protection for a worksheet is on or off.

    Like
        If Sheets("sheet1").ProtectContents Then
            'protected
        Else
            ' not protected
        End If

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,188

    Re: Show if the protection for a worksheet is on or off.

    "protect"

    The value 0 if the cell is not locked; otherwise returns 1 if the cell is locked.

    Note: This value is not supported in Excel for the web, Excel Mobile, and Excel Starter.
    Unfortunately, this does not do what you think/thought it does. It is checking if the cell is locked or not. It is NOT checking if the sheet is protected.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Show if the protection for a worksheet is on or off.

    Thanks guys. For clarity , I'm not trying to protect / unprotect the worksheet , only to indicate in a given cell whether it's on or off.

    I'm not sure it's possible , but wondered if someone knows a way. The cell might change colour as the protection changes.

    Jindon - thanks for your code , but I'm not sure how to apply your suggestion. Perhaps you could clarify.


  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,188

    Re: Show if the protection for a worksheet is on or off.

    Please re-read post #3. The formula does not check sheet protection, it checks if a cell is locked. I know you are not trying to protect/unprotect the sheet.

  6. #6
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Show if the protection for a worksheet is on or off.

    Thanks TMS. No, the formula doesn't the job. I couldn't get it working with CF..

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Show if the protection for a worksheet is on or off.

    CDandVinyl,

    If you want.

    1) To a standard code module.
    Function IsSheetProtected(r As Range) As Boolean
        Application.Volatile
        IsSheetProtected = r.Parent.ProtectContents
    End Function
    2) To Sheet code module
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Me.Calculate
    End Sub
    3) Select A1 and CF
    Formula
    =IssheetProtected(A1)

    4) When you protect sheet, you need to allow both [Select locked Cells] & [Select unlocked Cells]

    5) Each time you Lock/Unlock the sheet, you need to select any cell to recalculate the CF formula.

  8. #8
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Show if the protection for a worksheet is on or off.

    Thanks jindon. This works fine. I'm impressed!

    BTW With the CF option i can use colour but can't toggle green 'Protection on' , red 'Protection Off' text in E1. Could this be achieved with VBA in the Sheet code module?

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Show if the protection for a worksheet is on or off.

    2 ways

    1)
    Simple way is to color the cell in Green.
    So that the cell is always green when not protected and turns to red when protected via CF.

    2) If you want to control in CF then add another one
    formula
    =NOT(IsSheetProtected(A1))
    and format the cell in Green

  10. #10
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Show if the protection for a worksheet is on or off.

    Many Thanks - problem solved!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 11-21-2013, 11:08 AM
  2. [SOLVED] Row-by-row protection on a worksheet
    By oracle741 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-05-2013, 09:34 AM
  3. Vb and Protection of worksheet
    By flyinghigher2011 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-14-2013, 11:40 PM
  4. Worksheet Protection
    By Tommy T in forum Excel General
    Replies: 1
    Last Post: 11-15-2007, 08:11 PM
  5. Replies: 4
    Last Post: 05-02-2006, 11:55 AM
  6. Worksheet Protection
    By PA in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 08-20-2005, 10:05 AM
  7. worksheet protection
    By yemi in forum Excel General
    Replies: 3
    Last Post: 05-20-2005, 06:06 PM

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