Multiple Double Click Events on Different Ranges in 1 Worksheet

karenzh

New Member
Joined
Sep 8, 2022
Messages
3
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi everyone. I'm trying to simulate an interactive "dashboard" in Excel where double clicking specific ranges will Autofilter different parameters on another sheet.

My different double click events look like this:

1.

VBA Code:
If Not Intersect(Target, Range("L7:L166")) Is Nothing Then
    Dim Goal As String
    Goal = "*" & Cells(Target.Row, 7) & "*"
    
    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
End If

2.

VBA Code:
If Not Intersect(Target, Range("M7:M166")) Is Nothing Then
    Dim Goal As String
    Goal = "*" & Cells(Target.Row, 7) & "*"

    On Error Resume Next
    Sheets("Details").ShowAllData

    Sheets("Details").UsedRange.AutoFilter field:=1, Criteria1:=Goal
    Sheets("Details").Activate
End If

I'll have a lot of them. Ballpark ~20 ish on this one sheet. Does anyone have a method for doing this?

I have it semi working linked together using a solution like this: BeforeDoubleClick Event with multiple ranges
However the main issue with this method is that the filter doesn't reset properly between each doubleclick event. For reasons I'm unsure of, when a filter returns 0 values, it won't properly reset to "ShowAllData" when you do another double click event so that filter will not return values even if there are.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I'm not 100% clear on what it is you want - in both 1 & 2 above you're using the value (with wildcards) in the Target row - column G - as the filter criteria. Is it the case that you simply want to show all data if nothing is returned by the filter? If so, the following code should work for you. I'm also not sure what you mean by this:
I'll have a lot of them. Ballpark ~20 ish on this one sheet.
Do you mean that you have a different If statement depending on which column is the Target? As I said, in both cases above (clicking on columns L & M) you're still using column G values as the filter criteria.

Anyhow, see if this works for what you want (simply expand the range L6:M166 to whatever your total columns are).
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, cancel As Boolean)
    If Not Intersect(Me.Range("L6:M166"), Target) Is Nothing Then
        cancel = True
        Dim Goal As String, ws As Worksheet
        Set ws = Worksheets("Details")
        
        Goal = "*" & Cells(Target.Row, 7) & "*"
        With ws.UsedRange
            .AutoFilter 12, "Open"
            .AutoFilter 1, Goal
        End With
        If Application.CountA(ws.Range("A:A").SpecialCells(12)) = 1 Then ws.ShowAllData
        Application.Goto ws.Range("A1"), 1
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top