VBA Macro to enable auto filtering in excel.

Sometime, you want to enable the filtering mechanism that you enabled in excel worksheet to be reapplied automatically, then you need to use the following code as Macro which will do it for you:

Private Sub Worksheet_Calculate()

    If Me.FilterMode = True Then
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With

        With ActiveWorkbook
            .CustomViews.Add ViewName:="Mine", RowColSettings:=True
            Me.AutoFilterMode = False
            .CustomViews("Mine").Show
            .CustomViews("Mine").Delete
        End With


        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End If


End Sub

No comments:

Post a Comment

Thank You.

https://linwintech.blogspot.com/