Sub combinationFilter() 'Filtering based on selected combination Dim cell As Range, tableObj As ListObject, subSelection As Range Dim filterCriteria() As String, filterFields() As Integer Dim i As Integer 'If the selection is in a table and one row height If Not Selection.ListObject Is Nothing And Selection.Rows.Count = 1 Then Set tableObj = ActiveSheet.ListObjects(Selection.ListObject.Name) i = 1 ReDim filterCriteria(1 To Selection.Cells.Count) As String ReDim filterFields(1 To Selection.Cells.Count) As Integer ' handle multi-selects For Each subSelection In Selection.Areas For Each cell In subSelection filterCriteria(i) = cell.Text filterFields(i) = cell.Column - tableObj.Range.Cells(1, 1).Column + 1 i = i + 1 Next cell Next subSelection With tableObj.Range For i = 1 To UBound(filterCriteria) .AutoFilter field:=filterFields(i), Criteria1:=filterCriteria(i) Next i End With Set tableObj = Nothing End If End Sub
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter