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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

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