The attached sheet contains the following code I wrote. I'm trying to set the autofilter to display only the values I load into my array (even numbers 2 - 12 on column D). The code does not debug, but it doesn't work? The autofilter gets turned on but the criteria doesn't. If i remove the "Operator:=xlFilterValues" then the last value allocated to my array, which is "12" does get set. Not sure what is wrong.
Option Explicit
Option Base 1
Public Sub TestAutoFilterDelete()
Dim ws As Worksheet
Dim rng As Range
Dim arrCriteria() As Variant
Dim x As Integer, iteration As Integer
iteration = 1
For x = 2 To 12 Step 2
ReDim Preserve arrCriteria(iteration)
arrCriteria(iteration) = x
iteration = iteration + 1
Next x
Set ws = Outputs
Set rng = ws.Cells(1, 1).CurrentRegion
With ws
.AutoFilterMode = False
With .Range(rng.Address)
.AutoFilter
.AutoFilter Field:=4, Criteria1:=Array(arrCriteria), Operator:=xlFilterValues End With
End With
End Sub
Bookmarks