• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Auto filtering - VBA

MahanK

New Member
Hi All,

Can you please let me on below VBA code , I have recorded VBA to do some filtering on my data then I have added lines to unprotect then protect the sheet as below, now I want to allow user to filter one specific column to filter on sheet by adding to my current VBA, can you please help me in this regard:


Sub Piping()
ThisWorkbook.Worksheets("sheet1").Unprotect ("GEG")
' Piping Macro
'
'
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveSheet.Range("$A$2:$T$2095").AutoFilter Field:=21, Criteria1:="P"
ThisWorkbook.Worksheets("sheet1").Protect ("GEG")
End Sub
 
Hi,
.Autofilter turns auto filter on and off. so you need to include a check whether the filter is already on or not.
To autofilter only 1 column, say T, it can work via Range("T1:T2").AutoFilter.

Something like this perhaps works.
Code:
If Not ActiveSheet.AutoFilterMode Then
    Range("T1:T2").AutoFilter
End If
 
Back
Top