Filter Column by Another Column VBA Excel
My youtube video at the bottom of this article will walk you through the VBA code to filter one column by a different column in Excel.
The below image shows how to filter Column A by Column H. Please note that the two columns must have the same first cell value (Column A = Company and Column H = Company).
The below image shows where you click to bring this option up in Excel. Click "Advanced." List Range is what you want to filter and Criteria Range is the range that contains the values you want the List Range to be filtered by:
Here's the VBA code from this video:
Sub Macro3()
erowA = Range("A" & Rows.Count).End(xlUp).Row
erowI = Range("I" & Rows.Count).End(xlUp).Row
erowD = Range("D" & Rows.Count).End(xlUp).Row
erowH = Range("H" & Rows.Count).End(xlUp).Row
If Sheets("Sheet1").FilterMode Then
Sheets("Sheet1").ShowAllData
End If
Range("D1").Select
Selection.AutoFilter
Range("D1:D" & erowD).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("I1:I" & erowI), Unique:=False
ActiveSheet.ShowAllData
Range("A1").Select
Selection.AutoFilter
Range("A1:A" & erowA).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("H1:H" & erowH), Unique:=False
ActiveSheet.ShowAllData
End Sub
Here's the above code in image form if you want to write it out yourself: