Exceluser111
New Member
- Joined
- Jan 14, 2015
- Messages
- 7
I have the following macro:
However, it is filtering the entire table away as if there was no match, despite the value in D1 being a date in the same format as the dates listed in the column "Shipment_Date"
I don't know if there is specific ways to interact with tables created from queries, but I am not having any success with filtering the table by the date I want.
VBA Code:
Sub FilterByDate()
Dim targetDate As Date
Dim wsDashboard As Worksheet
Dim wsShippingQ As Worksheet
Dim tbl As ListObject
Dim colNum As Integer
'Define the worksheets
Set wsDashboard = ThisWorkbook.Worksheets("Dashboard_Today")
Set wsShippingQ = ThisWorkbook.Worksheets("ShippingQ")
'Get the target date from the Dashboard_Today worksheet
targetDate = wsDashboard.Range("D1").value
'set table to the tbl variable
Set tbl = wsShippingQ.ListObjects(1)
'Find the Shipment_Date column number
colNum = tbl.ListColumns("Shipment_Date").Index
'Filter the table based on the Shipment_Date column
tbl.Range.AutoFilter Field:=colNum, Criteria1:=targetDate, Operator:=xlFilterValues
End Sub
However, it is filtering the entire table away as if there was no match, despite the value in D1 being a date in the same format as the dates listed in the column "Shipment_Date"
I don't know if there is specific ways to interact with tables created from queries, but I am not having any success with filtering the table by the date I want.