Consulting

Results 1 to 5 of 5

Thread: Unprotect cell

  1. #1
    VBAX Regular
    Joined
    Dec 2004
    Posts
    26
    Location

    Unprotect cell

    On a password protected spreadsheet, is it possible, for example, to unprotect only cell B18 for editing if cell A12 had specific data put into it?


    Thanks for helping.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by outrider
    On a password protected spreadsheet, is it possible, for example, to unprotect only cell B18 for editing if cell A12 had specific data put into it?
    You could trap the event, unprotect the sheet, unlock the cell, and the protect the sheet.

    Private Sub Worksheet_Change(ByVal Target As Range) 
    On Error GoTo ws_exit:
        Application.EnableEvents = False
        If Target.Address = "$A$12" Then
            If Target.Value = "whatever" Then
                Me.Unprotect Password:="Bob"
                Me.Range("B18").Locked = False
                Me.Protect Password:="Bob"
            End If
        End If
    ws_exit:
        Application.EnableEvents = True
    End Sub

    This is worksheet event code, which means that it needs to be placed in the appropriate worksheet code module, not a standard 'code module. To do this, right-click on the sheet tab, select 'the View Code option from the menu, and paste the code in.

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Here's an example. It reprotects the cell if the A12 cell value changes. For clarity, the cell colour is changed to reflect protection status.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Regular
    Joined
    Dec 2004
    Posts
    26
    Location
    Thanks for the the quick reply.
    Works great.


    Outrider.

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Outrider,
    I put this together, based upon your question
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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