Filter using named cell

LC1234

New Member
Joined
Nov 10, 2005
Messages
12
How do I make this work? My code is:

Selection.AutoFilter Field:=1, Criteria1:=">=WBDate", Operator:=xlAnd, _
Criteria2:="<=WEDate"

WBDate is a cell that contains a beginning date
WEDate is a cell that contains an ending date
Both cells are vlookups and are formated as dates
AutoFilter Field 1 is the 1st column in my data and contains only dates

The code seems to work, except it says there's no records in my data that are between the two date ranges. That's not true. Can you not use a cell name as criteria in AutoFilter?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
You can, just not inside the quotes as you are currently using it.

This should work if the cells are dimmed as ranges in the macro
Code:
Selection.AutoFilter Field:=1, Criteria1:=">=" & WBDate, Operator:=xlAnd, _
Criteria2:="<=" & WEDate

If you are referring to named ranges on the worksheet (accessed from Insert\Name\Define), try:
Code:
Selection.AutoFilter Field:=1, Criteria1:=">=" & Range("WBDate").Value, Operator:=xlAnd, _
Criteria2:="<=" & Range("WEDate").Value
 
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,163,991
Messages
5,834,769
Members
430,319
Latest member
Excelhelppll

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