criteria field to auto filter

D

dhbyrne

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
 
D

Debra Dalgleish

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
'=====================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top