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?
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,081
Messages
5,570,086
Members
412,310
Latest member
mark884
Top