Double Click to Filter Multiple Columns

alexdowd2

New Member
Joined
Apr 15, 2022
Messages
19
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
I have 2 sheets, one is a library of sorts (Sheet1) that has an Id column and then corresponding filter values for columns on Sheet2. That Id column from Sheet1 is NOT on Sheet2. Conceptually, what I want to be able to do is click on the Id column on Sheet1, then filter Sheet2 based on the values in that Id's row, which correspond to values in columns on Sheet2 (the column header names are the same). For example, sample data may look like this:

Sheet1

IdColorMakeModel
1​
BlueHondaCivic
2​
GrayFordTaurus
3​
GreenHondaInsight
4​
GreenTeslaModel S

Sheet2

ColorMakeModel
BlueHondaCivic
GrayFordTaurus
GreenHondaInsight
GreenTeslaModel S

Use Case: I double click 1 on Sheet1 and that filters Sheet2 on all records where Color = Blue, Make = Honda, Model = Civic.
 
Once you have opened the immediate window, leave it open & then double-click in col A
Oh i think i might have a different version of excel, Ctrl +G doesn't bring up the immediate window. nothing happens in the immediate window when i double click
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
What happens if you click on View in the VB Editor & select immediate window?
 
Upvote 0
In that case it sounds as though the code is not running. Try closing Excel & re-opening it.
 
Upvote 0
In that case it sounds as though the code is not running. Try closing Excel & re-opening it.
I've done that multiple times now :(
The code is definitely running, it navigates (i added a Sheet.Activate line to go to the sheet) to the correct sheet and selects the correct columns (i can tell because the filter icon shows filters are applied) except instead of selecting the values it's clearing them.
 
Upvote 0
Just realised that I never posted the modified code. :(
Use
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.Column = 1 Then
      Cancel = True
      If Target.Value = "" Then Exit Sub
      Debug.Print "|" & Target.Offset(, 1).Value & "|", "|" & Target.Offset(, 2).Value & "|"
      With Sheets("Sheet2").Range("A1")
         .AutoFilter 1, Target.Offset(, 1)
         .AutoFilter 2, Target.Offset(, 2)
         .AutoFilter 3, Target.Offset(, 3)
      End With
   End If
End Sub
 
Upvote 0
Solution
Just realised that I never posted the modified code. :(
Use
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.Column = 1 Then
      Cancel = True
      If Target.Value = "" Then Exit Sub
      Debug.Print "|" & Target.Offset(, 1).Value & "|", "|" & Target.Offset(, 2).Value & "|"
      With Sheets("Sheet2").Range("A1")
         .AutoFilter 1, Target.Offset(, 1)
         .AutoFilter 2, Target.Offset(, 2)
         .AutoFilter 3, Target.Offset(, 3)
      End With
   End If
End Sub
Sorry I just got back to this thread. It still doesn't work. Here is a screenshot of what I'm seeing along with the real code. I have all the other filters commented out just for testing.


The selection I am making sure return the filter "Less Than 4 Hours"
 

Attachments

  • 1.PNG
    1.PNG
    18.7 KB · Views: 7
  • 2.PNG
    2.PNG
    10.3 KB · Views: 6
Upvote 0
When you run that, what does it say in the immediate window?
 
Upvote 0
|CRITICAL| |Less than 4 hours|

for context, Critical is the value in the first offset column
It also says those 2 things for all the filters even though there are definitely more values (verified manually)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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