+ Reply to Thread
Results 1 to 2 of 2

Allow filtering on protected sheet

Hybrid View

hasan mougharbel Allow filtering on protected... 12-15-2023, 06:52 AM
deadlyduck Re: Allow filtering on... 12-15-2023, 07:37 AM
  1. #1
    Forum Contributor
    Join Date
    11-06-2021
    Location
    Tripoli
    MS-Off Ver
    Still using 2007 in 2023
    Posts
    291

    Red face Allow filtering on protected sheet

    Hello everyone, I hope you're all doing well. I have a vba code that locks a sheet and unlocks specific columns.

    My only enquiry is how to apply a filter to the headers, or in other words, enable the 'Use Auto Filter' feature on that sheet.

    I've tried experimenting with this, but haven't been successful.

    Thanks a lot.

    My code
    Sub LockSpecificColumns()
        Dim ws As Worksheet
        Dim rngLocked As Range
        Dim rngUnlocked As Range
    
        ' Set the worksheet
        Set ws = ThisWorkbook.Sheets("Data")
        
        ' Set the ranges to be locked and unlocked
        Set rngLocked = ws.UsedRange
        Set rngUnlocked = Union(ws.Columns("B"), ws.Columns("C"), ws.Columns("D"), ws.Columns("E"), ws.Columns("H"), ws.Columns("F"), ws.Columns("G"))
    
        ' Lock the entire sheet
        ws.Cells.Locked = True
    
        ' Unlock specific columns
        rngUnlocked.Locked = False
        
        With Worksheets("Data")
        .Protect AllowFiltering:=True
        End With
            
        ' Protect the sheet
        ws.Protect
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: Allow filtering on protected sheet

    Removing the last line (ws.protect) seems to be the answer- you've already protected the worksheet in the preceding few lines so it looks like the last line overrides the settings.
    Excel 365 user. To unblock a downloaded macro-enabled workbook, go to your "Downloads" folder > right click on the workbook name > click 'Properties' > check the 'Unblock' checkbox. You can now open the workbook.

+ 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. [SOLVED] Filtering And Sorting On A Sheet With Protected Columns
    By Mvaldesi in forum Excel General
    Replies: 4
    Last Post: 04-21-2023, 07:08 PM
  2. [SOLVED] Filtering and sorting on protected sheet
    By ImranBhatti in forum Excel General
    Replies: 2
    Last Post: 09-27-2018, 10:59 AM
  3. [SOLVED] allow filtering in a protected sheet
    By sandordan_01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2018, 03:40 PM
  4. Filtering issues with a protected sheet
    By TPDave in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2014, 12:31 PM
  5. Allow table sorting/filtering in protected sheet.
    By rlbush2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2014, 03:55 PM
  6. filtering a protected sheet
    By deth in forum Excel General
    Replies: 1
    Last Post: 06-01-2012, 06:18 PM
  7. filtering in protected sheet
    By Yaheem in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-25-2006, 06:17 AM

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