Autofilter with headers in Row 2

Gtabtr1

New Member
Joined
Feb 15, 2017
Messages
39
I'm sure this is a simple answer but I'm fairly frustrated trying to get it to work and not being able to identify why it is not working. My data headers are in row 2. Most of Row 1 is empty, out of 16 used columns, only 2 have data. But I need my autofilter to use row 2 are the header row. I'm getting the dreaded "Autofilter method of range class failed". Please! Please! What am I missing?

Dim AreaList As Range
Dim area As Range
Set AreaList = Workbooks(Pretty).Sheets(List).Range("A2:A" & last)

Workbooks(Master).Sheets(Participants).Activate
Workbooks(Master).Sheets(Participants).Select
Dim RangetoFilter As Variant
Dim Headerrow As Variant
RangetoFilter = "A3:P" & Lastrow
Headerrow = "A2:P2"
For Each area In AreaList

ActiveSheet.AutoFilterMode = False
ActiveSheet.Range(Headerrow).Select
ActiveSheet.Range(Headerrow).AutoFilter
ActiveSheet.Range(RangetoFilter).AutoFilter Field:=5, Criteria1:=area, Operator:=xlFilterValues
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Do you have any blank rows within your data?
 
Upvote 0
Ok, one other thing, are your trying to filter for each individual value in the area list, or all of them?
 
Upvote 0
I'm trying to filter on one number at a time from a list where the number could be included once or 20 times for example. So one value at a time.
 
Upvote 0
Ok, how about
VBA Code:
   Dim AreaList As Range, Cl As Range

   Set AreaList = Workbooks(Pretty).Sheets(List).Range("A2:A" & last)

   With Workbooks(Master).Sheets(Participants)
      For Each Cl In AreaList
         .Range("A2:P2").AutoFilter 5, Cl.Value
         ' do something
      Next Cl
   End With
 
Upvote 0
I changed "C1" to "Area" to help me understand what it is but other than that I still get the "Autofilter method of range class failed" error on the ".Range("A2:P2").AutoFilter 5, Area.Value" line.

Cell A1 is empty. Headers start in A2. Does that matter?
 
Upvote 0
Is your data on a protected sheet and/or is it a structured table?
 
Upvote 0
No. It's just an Excel spreadsheet with data in A1:C42 but the area I need (numeric values) are in column A. A2 is the first value. A42 is the last numeric value.
 
Upvote 0
I was referring to the sheet that you are trying to filter, rather than the arealist.
 
Upvote 0

Forum statistics

Threads
1,214,848
Messages
6,121,914
Members
449,054
Latest member
luca142

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