
Originally Posted by
p45cal
This is a shot in the dark: try removing the line:
.Range("A1:AJ1").AutoFilter
altogether.
On the other hand, don't.
In your code:
.Range("A1:AJ1").AutoFilter
rng.AutoFilter Field:=6, Criteria1:=">="…
.Range("A1:AJ1") is the header row, but rng is the data body excluding the headers.
Normally, I'd expect the two .Autofilter lines to act on the same range. So for consistency, I'd have
Set rng = ws2.Range("A2:J" & lr)
changed to:
Set rng = ws2.Range("A1:J" & lr)
and later, change:
With ws2
.AutoFilterMode = False
.Range("A1:AJ1").AutoFilter
rng.AutoFilter Field:=6, Criteria1:=">=" & MinValue, Operator:=xlAnd, Criteria2:="<=" & MaxValue
End With
to just:
ws2.AutoFilterMode = False
rng.AutoFilter Field:=6, Criteria1:=">=" & MinValue, Operator:=xlAnd, Criteria2:="<=" & MaxValue