Coding text filters in Excel 2007
I am trying to use code to filter a spreadsheet dynamically based on the current date.
I am storing the date that I need to filter as "CurrDay" and I am trying to remember that stored date in my filtering algorithm. It doesn't work and I need to figure out how to do it in order to complete this code. Every time I run the code, it returns the CurrDay name in the filter instead of the date stored in the CurrDay variable.
I am missing something and I need some direction. Any help is appreciated.
THE CODE:
Sub Finishing_A59_Filter()
'
' Finishing_A59_Filter Macro
' This macro will activate the A59 and Filter it properly for standard orders
'
'This macro does not include the VMI and APS orders in the code
'
'
Dim Currday As Date
Currday = Date + 7
UName = Application.UserName
Workbooks.Open Filename:="G:\Copy Modified A59 5-19-2009.xlsm", UpdateLinks _
:=0
Range("M2").Select
ActiveCell.Value = Currday
Columns("Q:Q").Select
Selection.NumberFormat = "mm/d/yyyy"
' Filter the sheet to remove VMI and APS orders
ActiveSheet.Range("$A$3:$AA$2941").AutoFilter Field:=23, Criteria1:=Array( _
"01", "04", "06", "08", "09", "10", "15", "25", "="), Operator:=xlFilterValues
' Set the proper date range for the sheet - This needs to be seven days beyond the current date
ActiveSheet.Range("$A$3:$AA$2941").AutoFilter Field:=17, Criteria1:= _
"<=Currday", Operator:=xlAnd
0
smoothbassman
a source
to share
1 answer
You need to concatenate the variable with the criteria string.
ActiveSheet.UsedRange.AutoFilter Field:=17, Criteria1:= _
"<=" & Currday, Operator:=xlAnd
Also, it's better to use "UsedRange" instead of creating a large range, because it doesn't work if your data goes past your arbitrary range and is a waste of resources if it doesn't.
+1
a source to share