criteria field to auto filter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

ok that seems to work but the problem now is that the screen is blank, if i select the filter the date in the field is correct with the right criteria but i have to select OK for it to work, how can i get it to select OK automatically so that will display all the transaction dates...

thanks for this



The < operator should be enclosed in quotation marks, and followed by an
ampersand:

Selection.AutoFilter field:=4, Criteria1:="<" & lessdays
 
You could run a macro when the workbook opens. For example, place the
following code in the ThisWorkbook module, and the filter on the "Data"
sheet is updated when the workbook opens:

'==============================
Private Sub Workbook_Open()
Dim ws As Worksheet
Dim lessdays As Date
Set ws = Sheets("Data")

lessdays = Date - 30

'check for filter, turn on if none exists
If Not ws.AutoFilterMode Then
ws.Range("A1").AutoFilter
End If

'filter for current date - 30 days
ws.Range("A1").AutoFilter _
Field:=4, Criteria1:="<" & lessdays

End Sub
'=====================================
 
Back
Top