I'm trying to simulate an interactive "dashboard" in Excel where double clicking specific ranges will Autofilter different parameters on another sheet.
I'll have a lot of them, probably >10. Here's generally what I have so far:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
Application.EnableEvents = False
On Error GoTo ErrorRoutine
Dim Goal As String
Goal = "*" & Cells(Target.Row, 7) & "*"
If Not Intersect(Target, Range("L7:L166")) Is Nothing Then
On Error Resume Next
Sheets("Details").ShowAllData
Sheets("Details").UsedRange.AutoFilter field:=12, Criteria1:="Open"
Sheets("Details").UsedRange.AutoFilter field:=1, Criteria1:=Goal
Sheets("Details").Activate
Cancel = True
ElseIf Not Intersect(Target, Range("M7:M166")) Is Nothing Then
On Error Resume Next
Sheets("Details").ShowAllData
Sheets("Details").UsedRange.AutoFilter field:=1, Criteria1:=Goal
Sheets("Details").Activate
Cancel = True
ElseIf etc.etc.
End If
ErrorRoutine:
Application.EnableEvents = True
End Sub
The ElseIf chains just go on. It works but there's a big issue I just can't debug that I think has something to do with how I clear the filters with .ShowAllData between each If/Then.
For some reason whenever a filter returns 0 values, it won't properly reset to "ShowAllData" when you trigger another double click event that comes after it in the code. So that event's filter will not return any values even if there definitely are.
Anything weird in my code?