Hi there! I have a file that I am autofiltering by year and copying into another file. I have tried a few approachs below. It works if I just filter by one year and it works if I hard code the 3 years I want in the macro, but when I try to use array with the links, no information gets pulled in (but there is no error message). Is this possible? Any help would be appreciated!
'Dim arr As Variant
'arr = Array(ThisWorkbook.Worksheets("Linking Criteria").Range("L10").Value, _
ThisWorkbook.Worksheets("Linking Criteria").Range("L11").Value, _
ThisWorkbook.Worksheets("Linking Criteria").Range("L12").Value)
With ws.Range("A1", ws.Cells(lr, lc))
'.AutoFilter Field:=6, Criteria1:=ThisWorkbook.Worksheets("Linking Criteria").Range("L10").Value ' works with single year link
.AutoFilter Field:=6, Criteria1:=Array("2020", "2021", "2022"), Operator:=xlFilterValues 'array works when hard coded
'.AutoFilter Field:=6, Criteria1:=Array(arr), Operator:=xlFilterValues 'array doesn't work with links
.SpecialCells(xlCellTypeVisible).Copy
End With
ThisWorkbook.Activate
Worksheets("Disb Import").Range("a5").PasteSpecial xlPasteValues
'Dim arr As Variant
'arr = Array(ThisWorkbook.Worksheets("Linking Criteria").Range("L10").Value, _
ThisWorkbook.Worksheets("Linking Criteria").Range("L11").Value, _
ThisWorkbook.Worksheets("Linking Criteria").Range("L12").Value)
With ws.Range("A1", ws.Cells(lr, lc))
'.AutoFilter Field:=6, Criteria1:=ThisWorkbook.Worksheets("Linking Criteria").Range("L10").Value ' works with single year link
.AutoFilter Field:=6, Criteria1:=Array("2020", "2021", "2022"), Operator:=xlFilterValues 'array works when hard coded
'.AutoFilter Field:=6, Criteria1:=Array(arr), Operator:=xlFilterValues 'array doesn't work with links
.SpecialCells(xlCellTypeVisible).Copy
End With
ThisWorkbook.Activate
Worksheets("Disb Import").Range("a5").PasteSpecial xlPasteValues