filter out rows based in drop down field

%3CLINGO-SUB%20id%3D%22lingo-sub-2244389%22%20slang%3D%22en-US%22%3Efilter%20out%20rows%20based%20in%20drop%20down%20field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2244389%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20looking%20to%20use%20macro's%20to%20create%20a%20function%20that%20will%20hide%20selected%20rows%20in%20a%20sheet%20based%20on%20the%20entry%20of%20a%20drop%20down%20field%2C%20I%20haven't%20really%20had%20much%20experience%20with%20this%20sort%20of%20thing%20before.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20solution%20will%20be%20used%20in%20an%20excel%20dashboard%20tracking%20various%20metrics%2C%20and%20having%20this%20automatic%20filter%20will%20make%20using%20the%20workbook%20easier.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20included%20a%20document%20which%20has%20an%20example%20of%20what%20I%20am%20working%20with%20and%20will%20hopefully%20help%20with%20a%20solution..%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2244389%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2244419%22%20slang%3D%22en-US%22%3ERe%3A%20filter%20out%20rows%20based%20in%20drop%20down%20field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2244419%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F984913%22%20target%3D%22_blank%22%3E%40DBreezy92%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESee%20the%20attached%20version%20-%20it's%20now%20a%20.xlsm%20workbook%20since%20it%20contains%20VBA%20code.%3C%2FP%3E%0A%3CP%3ETo%20inspect%20the%20code%2C%20right-click%20the%20sheet%20tab%20and%20select%20'View%20Code'%20from%20the%20context%20menu.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

I am looking to use macro's to create a function that will hide selected rows in a sheet based on the entry of a drop down field, I haven't really had much experience with this sort of thing before.

 

The solution will be used in an excel dashboard tracking various metrics, and having this automatic filter will make using the workbook easier.

 

I've included a document which has an example of what I am working with and will hopefully help with a solution..

3 Replies

@DBreezy92 

See the attached version - it's now a .xlsm workbook since it contains VBA code.

To inspect the code, right-click the sheet tab and select 'View Code' from the context menu.

I have copied the code to my real world example, changed the cell referencing the drop down list and receive the following message;

showalldata method of worksheet class failed

Any ideas?

@DBreezy92 

Does it work better if you change the code in the worksheet module to

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo ExitHere
    If Not Intersect(Range("A2"), Target) Is Nothing Then
        Application.EnableEvents = False
        If Range("A2").Value = "" Then
            If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
        Else
            Range("A5").CurrentRegion.AutoFilter Field:=2, Criteria1:=Range("A2").Value
        End If
    End If
ExitHere:
    Application.EnableEvents = True
End Sub