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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

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