Say for example I have this table:
How can I make it so that when I double click on the header "verb", it filters the table to show only the rows that contains X in that header's column. And when I double click on the header again the filters gets removed, and if I clicked on another header while the table is already filtered, it gets removed first before filtering it.
I used this VBA code:
It works, however it doesn't remove the filter when I double click on the same header again, and it doesn't remove previous filters before filtering another column.
Any help would be much appreciated!
How can I make it so that when I double click on the header "verb", it filters the table to show only the rows that contains X in that header's column. And when I double click on the header again the filters gets removed, and if I clicked on another header while the table is already filtered, it gets removed first before filtering it.
I used this VBA code:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Application.Intersect(Target, Range("A1:D1")) Is Nothing Then
Cancel = True
If Me.AutoFilterMode Then
Me.AutoFilterMode = False
Else
Me.Range("A1:D1").AutoFilter Field:=Target.Column, Criteria1:="X"
End If
End If
End Sub
It works, however it doesn't remove the filter when I double click on the same header again, and it doesn't remove previous filters before filtering another column.
Any help would be much appreciated!