VBA to autofilter a table rather than range.

Godders199

Active Member
Joined
Mar 2, 2017
Messages
313
Office Version
  1. 2013
Hello, I am trying to code in a Filter into a report whichdownloads into excel as Table rather than range.
I have to create an additional column and header, by justdoing Range(“i1”).Value=”Adviser”
I Then have this code for the filter, however whatever I try,it errors on “icol = lo.ListColumns("Adviser").Index” Saying Subscript out of range. When I look at the Spreadsheet the curser isalways in cell J2
Is it therefore not recognising the header name I haveadded, or is there another issue. Or alternativeway to code this. I have triedrecording, but every time I press refresh it generates a different tablenumber.
Dim Daterng As Long
Dim Daterng1 As Long
Dim lo As ListObject
Daterng = Sheets("home").Range("D6")
Daterng1 = Sheets("home").Range("D7")


Sheets("Failure Reasons").Select
If ActiveSheet.AutoFilterMode ThenActiveSheet.AutoFilter.ShowAllData
Set lo = Sheets("Failure Reasons").ListObjects(1)
icol = lo.ListColumns("Adviser").Index
lo.Range.AutoFilterField:=icol, Criteria1:= _
Array("FDMA", "HSBCMA", "MPM","MSBMA", "MRO", "LCVMPM"),Operator:=xlFilterValues

Sheets("FailureReasons").Range("a:j").AutoFilter Field:=10,Criteria1:=">=" & Daterng, Criteria2:="<=" &Daterng1, Operator:=xlFilterValues

 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
The error indicates that your table does not contain a column whose header is Adviser. Is this the case? If not, check for a spelling error, extra spaces, etc.
 
Upvote 0
thanks, yes it is there and spelling correct and no extra spaces, I will keep playing
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

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