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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

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