Filter Tables Across Excel Worksheets with a VBA Double-Click Macro
Question details
Create an Excel macro that filters tables on multiple worksheets using an item code selected on a Data worksheet.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user wants to double-click an item-code cell on a Data worksheet and filter related tables on other worksheets.
- Observed behavior
- The desired result is for each mapped table to show rows matching the selected item code.
Identify the Data worksheet's item-code range, each target worksheet and table name, and the item-code column header. Use desktop Excel with macros enabled and save the workbook as an Excel Macro-Enabled Workbook (.xlsm).
Use a Workbook Event to Filter Mapped Excel Tables
Use this approach to filter several tables whenever you double-click an item code in a specified range on the Data worksheet.
The workbook-level SheetBeforeDoubleClick event reads the selected cell and applies the same filter to each mapped table. Replace the example sheet names, table names, range, and column header with those in your workbook.
Existing filters on other columns remain in place. If an error occurs partway through the list, earlier tables may already have been filtered.
Click inside each target table and check its name on the Table Design tab. Confirm that each table has an item-code column with the same header, or adjust the code to use a different header for each table.
In desktop Excel, select Developer > Visual Basic. In the Project Explorer, expand your workbook and double-click ThisWorkbook.
Paste the following code into ThisWorkbook. Change Data and B2:B1000 to your source sheet and range; change the worksheet and table pairs and Item Code to match your target tables: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) Dim targets As Variant, pair As Variant Dim itemCode As String Dim tbl As ListObject If Sh.Name <> "Data" Then Exit Sub If Target.CountLarge <> 1 Then Exit Sub If Intersect(Target, Sh.Range("B2:B1000")) Is Nothing Then Exit Sub If IsError(Target.Value2) Then Exit Sub itemCode = Trim$(CStr(Target.Value2)) If Len(itemCode) = 0 Then Exit Sub Cancel = True targets = Array(Array("Orders", "OrdersTable"), Array("Stock", "StockTable")) On Error GoTo FilterError For Each pair In targets Set tbl = ThisWorkbook.Worksheets(pair(0)).ListObjects(pair(1)) tbl.Range.AutoFilter Field:=tbl.ListColumns("Item Code").Index, Criteria1:=itemCode Next pair Exit Sub FilterError: MsgBox "Could not filter all tables. Check the sheet names, table names, and Item Code header. " & Err.Description, vbExclamation End Sub
Save the file as an .xlsm workbook, enable macros if prompted, and double-click an item code in the configured Data range. Open each target worksheet to verify that its table shows matching rows.

Work with Excel Tables in WPS Spreadsheet
WPS Office is a free, lightweight alternative for everyday spreadsheet work. Its familiar interface and Excel format compatibility make it easy to move between office suites. The Excel workbook event described here may not run the same way in WPS, so verify macro compatibility before migrating an automated workbook.

Frequently Asked Questions
Where do I paste the double-click macro?
In desktop Excel, open Developer > Visual Basic and paste the Workbook_SheetBeforeDoubleClick procedure into ThisWorkbook, not a standard module.
Why does double-clicking an item code do nothing?
Check that macros are enabled, the file is saved as .xlsm, and the cell is on the worksheet and within the range specified in the event code. Blank cells and cells containing errors are ignored.
Can the macro filter tables with different item-code headers?
Yes. Change the target mapping to include a column header for each table, then use that mapped header in tbl.ListColumns instead of the shared "Item Code" value.
How do I clear the filters after using the macro?
On each target worksheet, open the filter dropdown for the item-code column and select Clear Filter From that column. This leaves filters on other columns unchanged.




