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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,884
Messages
6,181,556
Members
453,053
Latest member
Kiranm13

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