Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default autofilter criteria

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 301
Default autofilter criteria

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

"Knox" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default autofilter criteria

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

"Bob Umlas" wrote:

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

"Knox" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default autofilter criteria

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)

Knox wrote:

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

"Bob Umlas" wrote:

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

"Knox" wrote in message
...
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






--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selection.AutoFilter Field / Criteria = criteria sometimes non-existing on worksheet markx Excel Programming 1 November 24th 06 02:52 PM
Autofilter criteria not yet known JeffMelton Excel Programming 1 July 25th 06 08:12 AM
AutoFilter criteria Mark Excel Programming 1 November 2nd 05 12:08 PM
AutoFilter Criteria VBA EstherJ Excel Programming 2 August 20th 04 12:54 PM
VBA Autofilter Criteria Brandon[_5_] Excel Programming 1 November 7th 03 12:40 PM


All times are GMT +1. The time now is 11:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"