Lock filters

lukasz_rz

New Member
Joined
Oct 13, 2013
Messages
48
Hi Guys.

Is there a possibility in excel to lock the filters? Meaning that I do set up some filters for certain columns and I want prevent other file users to modify it ? Note - I do not want to lock cells to be edited, just filters.


Or maybe is there a simple clever macro that would show a pop-up window every time someone is trying to change a filter?

Thanks a lot in advance.
 
This should be more robust than the previous code.
VBA Code:
Sub lukasz()
    Dim Rng As Range
    Dim Cnt As Long, fltr As Object
    
    Application.ScreenUpdating = False
    With ActiveSheet.AutoFilter
        .Parent.Unprotect Password:="Pword"
        Set Rng = .Range
        Set fltr = .Filters
        With .Filters
            For Cnt = 1 To .Count
                If Cnt <> 7 Then
                    With .Item(Cnt)
                        If .On Then
                            Select Case .Operator
                                Case 0: Rng.AutoFilter Cnt, .Criteria1, , , False
                                Case 1, 2: Rng.AutoFilter Cnt, .Criteria1, .Operator, .Criteria2, False
                                Case 3 To 6: Rng.AutoFilter Cnt, , .Operator, , False
                                Case 8: Rng.AutoFilter Cnt, .Criteria1.Color, .Operator, , False
                                Case Else: Rng.AutoFilter Cnt, .Criteria1, .Operator, , False
                            End Select
                        Else
                            Rng.AutoFilter Cnt, , , , False
                        End If
                    End With
                End If
            Next Cnt
        End With
        .Parent.Protect Password:="Pword", Contents:=True, AllowFiltering:=True
    End With
End Sub
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,972
Messages
6,128,035
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top