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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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
 
Upvote 0
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,
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,428
Members
448,961
Latest member
nzskater

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
Back
Top