+ Reply to Thread
Results 1 to 3 of 3

Protect & unprotect worksheet Macros - supplementary issue

Hybrid View

  1. #1
    Registered User
    Join Date
    03-20-2009
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    56

    Protect & unprotect worksheet Macros - supplementary issue

    All,

    I need further help with this code.

    When I run the protect macro I want only allow users to select unlocked cells for input. I have played around a bit recording another macro and then dumping bits of text into the code that was supplied in answer to my earlier thread but to no avail


    Sub UnprotectAllSheets()
        Dim x As Long
    
        For x = 1 To Sheets.Count
            Sheets(x).Unprotect
        Next x
    
    End Sub
    Sub ProtectAllSheets()
        Dim x As Long
        
        For x = 1 To Sheets.Count
            Sheets(x).Protect
        Next x
    
    End Sub
    What code do I need to add so that I achieve my aim of allowing only unlocked cells to be selected.

    All 14 tabs on the workbook are set with appropriate cells locked/unlocked.

    Thanks for your help in anticipation.

    Best regards,

    David
    Last edited by David_S_Walker; 03-31-2010 at 07:40 AM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile Re: Protect & unprotect worksheet Macros - supplementary issue

    Good morning David_S_Walker

    Just use this line directly under the "Protect..." line. This function will only affect protected sheets, so you shouldn't need to unset it again in your unprotect macro, but if you need to remove it, change the flag to xlNoRestrictions.
    Sheets(x).EnableSelection = xlUnlockedCells
    I would suggest incroporating it into your routine using the With / End With construct thus :
    Sub ProtectAllSheets()
    Dim x As Long
        For x = 1 To Sheets.Count
            With Sheets(x)
                .Protect
                .EnableSelection = xlUnlockedCells
             End With
        Next x
    End Sub
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    03-20-2009
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Protect & unprotect worksheet Macros - supplementary issue

    Perfect thank you Dominic!
    Last edited by David_S_Walker; 03-31-2010 at 07:40 AM.

+ 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