'data is filtered
Sub Filtration(mainsheet As Worksheet, lastrow As Long)
Application.ScreenUpdating = False
With mainsheet
'filters
.Range("$A$12:$J$" & lastrow).AutoFilter Field:=7, Criteria1:="TRUE"
.Range("$A$12:$J$" & lastrow).AutoFilter Field:=10, Criteria1:="TRUE"
HideAutoFilterDropdowns
End With
Application.ScreenUpdating = True
End Sub
Sub HideAutoFilterDropdowns()
With Range("A12")
.AutoFilter Field:=1, VisibleDropDown:=False
.AutoFilter Field:=2, VisibleDropDown:=False
.AutoFilter Field:=3, VisibleDropDown:=False
.AutoFilter Field:=4, VisibleDropDown:=False
.AutoFilter Field:=5, VisibleDropDown:=False
.AutoFilter Field:=6, VisibleDropDown:=False
.AutoFilter Field:=7, VisibleDropDown:=False 'problem is here
.AutoFilter Field:=8, VisibleDropDown:=False
.AutoFilter Field:=9, VisibleDropDown:=False
.AutoFilter Field:=10, VisibleDropDown:=False
End With
End Sub
What happens in the code above is I have a set of data on my sheet and it is filtered by field number 7 and 10 (column G & J). I then want to hide the drop down arrows. It works for 1-6 & 8-10, but when I try to hide column 7 it unfilters the data (counter to what the Filtration function did).
You need to leave your
Criteria1:=
code in the line. Once you remove that Criteria and runHideAutoFilterDropdowns()
you are actually telling it to remove the Criteria filter.You can also insert Sub "HideArrows()" found at Hide Arrows in Excel AutoFilter. The original code has been modified to fit your specific needs with comments.
I was having the same issue and wanted to share this solution that was found among numerous opened tabs regarding this topic. Hopefully this will be helpful to others like me who are searching message boards for help and answers.