PDA

View Full Version : Apply AutoFilter based on selected cell in another sheet



kvinay_00
11-10-2019, 08:34 PM
Hello,

I am trying to create a VBA code to apply Auto Filter based on selected cell in another sheet (same workbook). I am not an expert, tried using vlookup function after creating a table of cell references. I am attaching sample file for reference.

Request help from the experts in the group to guide on this.

Thanks in advance!

Vinay

mana
11-11-2019, 02:57 AM
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Intersect(Target(1), Range("D7:H10")) Is Nothing Then Exit Sub

Worksheets("sheet2").Activate
With ActiveSheet.Range("D6").CurrentRegion
.AutoFilter
.AutoFilter Field:=1, Criteria1:=Cells(Target(1).Row, "D").Value
.AutoFilter Field:=2, Criteria1:=Cells(6, Target(1).Column).Value
End With

End Sub

kvinay_00
11-11-2019, 03:53 AM
Great! Thank you mana so much for your valuable help!