Double-click event macro auto filter multiple columns on different worksheet

ac7

New Member
Joined
Jul 26, 2023
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hello -

I am new to the forum and am hoping someone can help me with this question. I have a spreadsheet with 2 worksheets: Orders, and Filtered.

Orders:

1690396563191.png


Filtered:

1690396740033.png


This is really oversimplified, but I am unable to upload my full spreadsheet. I am looking to have a double-click event macro (or whatever else would be appropriate) trigger on the Orders worksheet when an order number is double-clicked. I would then like to have the Filtered worksheet automatically filter to the order number and also filter the Short? column to only "Y". So if order 164893 on the Orders worksheet was double-clicked, I'd like to only see "Y" shortages for that specific order on the Filtered worksheet.

1690396949945.png


Thank you in advance for the help!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Please try the following on a copy of your workbook. Right-click on the Orders tab name, select View Code, and paste the code below into the window that appears on the right of the screen. Save the file as a macro-enabled workbook.
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column <> 1 Then Exit Sub
    Application.EnableEvents = False
    Cancel = True
    Dim s As String: s = Target.Value2
    If s <> "" Then
        With Worksheets("Filtered").Range("A1").CurrentRegion
            .AutoFilter 1, s
            .AutoFilter 2, "Y"
        End With
        Application.Goto Worksheets("Filtered").Range("A1")
    End If
    Application.EnableEvents = True
End Sub

The Filtered sheet before double clicking on the 123456 order on the Order sheet:
Book1
AB
1OrdersShort?
2123456Y
3123456Y
4158285N
5164893Y
6164893N
7164893Y
Filtered


And after double clicking on the 123456 order on the Order sheet:
Book1
AB
1OrdersShort?
2123456Y
3123456Y
8
Filtered
 
Upvote 1
Solution
Actually, one other question. I would like to add this auto filter to another worksheet called "Purchases". It will also filter the Filtered worksheet, but different columns. I was able to modify the code just fine, however, if I ran the macro from the Orders worksheet first, it's not filtering correctly because it's not removing the existing filter on column A. Is there a line of code I can enter that will clear the existing filters on column A or column S on the Filtered worksheet before running the rest of the macro?
 
Upvote 0
Actually, one other question. I would like to add this auto filter to another worksheet called "Purchases". It will also filter the Filtered worksheet, but different columns. I was able to modify the code just fine, however, if I ran the macro from the Orders worksheet first, it's not filtering correctly because it's not removing the existing filter on column A. Is there a line of code I can enter that will clear the existing filters on column A or column S on the Filtered worksheet before running the rest of the macro?
Immediately after If s <> "" Then put this:
Worksheets("Filtered").AutoFilter.ShowAllData
 
Upvote 1

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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