gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,341
- Office Version
- 365
- Platform
- Windows
I have this code that works. But if for some reason someone adds or deletes a column (which they shouldn't do, but it happens) the code will not work properly
Is there any way to change it so it looks for a specific field in the table to do the filter.
This is a Table that's being filtered (tblSQD). In the code I show the names of the equivalent fields
Thanks for the help
Is there any way to change it so it looks for a specific field in the table to do the filter.
This is a Table that's being filtered (tblSQD). In the code I show the names of the equivalent fields
Code:
Sub ApplyFilters()
'SQD Tabe is Filtered based on ItemID and Dates set on Search tab
Sheets("SQD").Activate
Range("A6").Activate
'Reset any previous filters
If ActiveSheet.AutoFilterMode Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
'Filter SQD to Match Search
'Table Field: ItemID_Match
ActiveSheet.ListObjects("tblSQD").Range.AutoFilter Field:=83, Criteria1:= _
"<>"
'Table Field: RFQDate_Match
ActiveSheet.ListObjects("tblSQD").Range.AutoFilter Field:=84, Criteria1:= _
"<>"
'Table Field: QuoteDate_Match
ActiveSheet.ListObjects("tblSQD").Range.AutoFilter Field:=85, Criteria1:= _
"<>"
'Table Field: QuoteExpiration_Match
ActiveSheet.ListObjects("tblSQD").Range.AutoFilter Field:=86, Criteria1:= _
"<>"
ActiveSheet.Range("A5").Select
End Sub
Thanks for the help