Godders199
Active Member
- Joined
- Mar 2, 2017
- Messages
- 313
- Office Version
- 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
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