Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Named Range as Criteria in Autofilter

Status
Not open for further replies.

DHGranstrand

Technical User
Oct 15, 2007
2
US
I am trying to autofilter a report that has a variable number of lines month to month to display only certain employees data.

I have a named range ("ShowNames") that I want Autofilter to use as the filter values.

The report is emailed to me monthly so I run the macro from a second Excel workbook which also has the named range.

The macro runs fine except that it only filters on the first value in the named range.

Here is the code:

Sub AutofilterNames()

Dim a1 As Variant

a1 = Range("ShowNames").Value

' Select Report To Filter
Windows("MasterReport.xls").Activate

' Position Curser For Range Selection
Range("A1").Select

' Autoselect Range of Data & Turn Filter On

ActiveSheet.Range(Selection.End(xlToRight), Selection.End(xlDown)).Autofilter Field:=1, _
Criteria1:=a1, Operator:=xlFilterValues

End Sub

Thanks for the help!!
 




Hi,

How do you intend to use the named range?

1. In a loop?

2. As the row source to a control?

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
I want to use the named range as the criteria for the autofilter.

ActiveSheet.Range(Selection.End(xlToRight), Selection.End(xlDown)).Autofilter Field:=1, _
Criteria1:=a1, Operator:=xlFilterValues
 



You cannot use a multi-cell range in a criteria.

You can only use ONE value per criteria.

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top