VBA Autofilter commands

tanny81

Board Regular
Joined
Mar 2, 2006
Messages
175
Hi All,

I am currently using the following code which filters a table of data for rows which begin with the value of the StartDate range.
Code:
Selection.AutoFilter Field:=7, Criteria1:=StartDate & "*"

In this code "*" indicates that the filter should use Auto Filter > Custom > Begins With

Does anybody know what charactor i should use to filter for the following:
Greater than or equal to
Less than or equal to
equal to

Thanks,
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Joined
Jul 30, 2006
Messages
3,656
tanny81,

Try recording several small macros, one for each of the following, to see the code that they create:
Greater than or equal to
Less than or equal to
equal to


Have a great day,
Stan
 

tanny81

Board Regular
Joined
Mar 2, 2006
Messages
175
Hi All,

I've solved the first problem, and can now get the autofilter to work as intended, however it returns no result when run using vba.

The code is
Code:
Selection.AutoFilter Field:=7, Criteria1:=">=" & StartDate, Operator:= _
        xlAnd, Criteria2:="<=" & EndDate
Where the ranges both equal dates. Doe's anybody know what would cause this?

Thanks,
 

tanny81

Board Regular
Joined
Mar 2, 2006
Messages
175
Ok,

I might have part of the solution to this. If i manually perform a text to columns function on the relevant field and then run my macro it seems to work ok. However, if i get a macro to run the text to columns function it removes the leading zero from the dates which are the 9th or earlier and then the auto filter doesn't work again.

Is there anything i can do with my code to resolve this?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,323
Messages
5,769,454
Members
425,549
Latest member
Bartekelese

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top