Criteria field for autofilter

D

dhbyrne

Hi
I am trying to write a macro that will use the autofilter function in Excel. I have a list of customers transactions and
I have a table with 5 columns, account no, account name etc and the 4th column is date of last transaction. The date of last transaction tells me the last time a customer has bought something off me. I use the record macro button and it gave me the following cod

selection.autofilter field:=4, criteria1:="01/01/2004", xlAnd

I tried to modify the code but i keep getting errors
I want it to lost all the transactions that are greater that today - 30 days, so i had something like thi

set Lessdays=date 'this gave me todays dat
lessdays=(lessdays - 30) ' this gave me todays date - 30 days wehich is the 15/12.200

selection.autofilter field:=4, criteria1:= < lessdays , xlAnd
This gives me an error like end of expressen expected and it highlights the "<". I have tried many variations but none wor

I also want to try and say greater than 30 days but less than 60 etc.

I need this to watch my customers to ensure that they buy off me and i dont loose any

thanks in advanc
 
D

Debra Dalgleish

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

Selection.AutoFilter field:=4, Criteria1:="<" & lessdays
 
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
 

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

Similar Threads

criteria field to auto filter 1
AutoFilter Criteria in VBA 13
Automated autofilter error 1
Custom filter 26
Autofilter in a macro 1
Dydnamic date in an autofilter 2
Problem using Autofilter 1
Filtering/Excluding Values 1

Top