Results 1 to 4 of 4

Cell range protect/unprotect toggle

Threaded View

  1. #2
    Forum Contributor
    Join Date
    03-30-2007
    Location
    London, UK
    MS-Off Ver
    Microsoft Office 2007
    Posts
    317

    Smile Solved! I managed to work it out

    Although I don't know how efficient my code is, I managed to work it out. I now have the code below, I also change the background colour of the cells depending whether they are locked or not.

    Of course all my knowledge gain here is from the homework from previous code that I have learned of you guys, so thank you so much for all your past efforts.

    Now I just need to tweak the code so that it can be called from muliple sheets.

    EDIT: Solved that also, changed all the 'Sheet1' references to 'ActiveSheet'.

    Below is the code:
    Sub Protect()
        Dim i As Integer
            Sheet1.Unprotect "Password"
         'My Code starts here
        If Range("A8:B20").Locked = False Then
        Range("A8:B20").Locked = True
        For i = 8 To 20
        Cells(i, 1).Interior.ColorIndex = 35
        Cells(i, 2).Interior.ColorIndex = 35
        Next i
        Else
        Range("A8:B20").Locked = False
        For i = 8 To 20
        Cells(i, 1).Interior.ColorIndex = 2
        Cells(i, 2).Interior.ColorIndex = 2
        Next i
          'My Code ends here
          End If
                Sheet1.Protect "Password"
                Sheet1.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
            , AllowSorting:=True, AllowFiltering:=True
            Sheet1.EnableSelection = xlUnlockedCells
           
        End Sub
    Last edited by Zyphon; 02-21-2008 at 06:27 AM.

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