Consulting

Results 1 to 4 of 4

Thread: Re-lock a Column after its been unlocked upon cell exit

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Re-lock a Column after its been unlocked upon cell exit

    I have a worksheet that I've unlocked a column (A), so that the user can enter an x in a specific row, however, I want that column to be locked again once any row in Column (A) is changed.
    How can I re-lock column (A) once a change is made.
    This is what I've tried amoung other things that will not work.
    Column A is Unlocked, but the rest of the sheet is still protected at this point.

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, Range("A2:A65536")) Is Nothing Then
                ActiveSheet.Range("A2:A65536").Locked = True
                ActiveSheet.Protect
        End If
    End Sub
    I keep getting this Error:
    unable to set the locked property of the range class 1004

  2. #2
    VBAX Contributor rollis13's Avatar
    Joined
    Jun 2013
    Location
    Cordenons
    Posts
    146
    Location
    You need to UnProtect the sheet before changing the cell property (or format).
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, Range("A2:A65536")) Is Nothing Then
            ActiveSheet.Unprotect
            ActiveSheet.Range("A2:A65536").Locked = True
            ActiveSheet.Protect
        End If
    End Sub

  3. #3
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Hi rollis13

    Thanks, that code works. I thought I had posted a THANK YOU note earlier, but didn't see it showing up.

  4. #4
    VBAX Contributor rollis13's Avatar
    Joined
    Jun 2013
    Location
    Cordenons
    Posts
    146
    Location
    Glad I was able to help .

Posting Permissions

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