autofilter criteria

G

Guest

I have a macro with this code:
Dim i As Long
Dim BMP As Variant
Dim EMP As Variant
Dim RSE As String * 25
For i = 3 To 3
RSE = Worksheets(1).Range("F" & i).Value
BMP = Worksheets(1).Range("D" & i).Value
EMP = Worksheets(1).Range("E" & i).Value
Sheets("TSTF").Select
Selection.AutoFilter Field:=1, Criteria1:=RSE
Selection.AutoFilter Field:=2, Criteria1:=">=BMP", Operator:=xlAnd, _
Criteria2:="<=EMP"
Range("A2:M13806").Select
Selection.Copy
etc. etc.

BMP and EMP are reading numbers like 2.57 and 5.14. If i put those numbers
where the variables are in the critereria code, it works. Why won't it work
with the variables? RSE is working but not BMP and EMP. thank you
 
B

Bob Umlas

Criteria1:=">=BMP" is literally looking for greater or equal to the letters
B M P. You need
Criteria1:=">" & BMP

similarly for <=EMP -- Criteria2:="<=" & EMP
Bob Umlas
Excel MVP
 
G

Guest

Thank you, that worked! Why does RSE work one way and BMP and EMP work a
different way?
 
D

Dave Peterson

This line:

Selection.AutoFilter Field:=1, Criteria1:=RSE
is treating RSE as a variable.

If you had used similar syntax, you would have had the same kind of problem:

Selection.AutoFilter Field:=1, Criteria1:="=RSE"
(would fail)

Selection.AutoFilter Field:=1, Criteria1:="=" & RSE
(would work)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top