Filter Data From Drop Down List Selection In Two Worksheets With VBA Code

PHOTO EMBED

Wed Sep 08 2021 05:54:20 GMT+0000 (Coordinated Universal Time)

Saved by @cnewnham #vba

Private Sub Worksheet_Change(ByVal Target As Range) 'Filter Data From Drop Down List Selection In Two Worksheets With VBA Code. If your drop down list cell in Sheet1, and the filtered data in Sheet2, when choosing one item from the drop down list, another sheet will be filtered out.
'Updateby Extendoffice
'Note: In the above code: A2 is the cell which contains the drop down list, and Sheet2 is the worksheet contains the data you want to filter. The number 1 in the script: AutoFilter 1 is the column number that you want to filter based on. You can change them to your need.
' 2. From now on, when you select one item from the drop down list in Sheet1, and the corresponding data will be filtered out in Sheet2, see screenshot:
    On Error Resume Next
    If Not Intersect(Range("A2"), Target) Is Nothing Then
        Application.EnableEvents = False
        If Range("A2").Value = "" Then
            Worksheets("Sheet2").ShowAllData
        Else
            Worksheets("Sheet2").Range("A2").AutoFilter 1, Range("A2").Value
        End If
        Application.EnableEvents = True
    End If
End Sub
content_copyCOPY