Auto Filter Criteria

  • Thread starter Thread starter David
  • Start date Start date
D

David

I am trying to filter a worksheet using a Macro that
contain a variable value (PR). When I run the Macro I can
get the Auto Filter command to returm the proper records
by setting Criteria1 = PR. If I try to use the variable
value as a wild card so that any record that contains this
value I get a complie error. Criteria2 = *PR*. The only
way I can set the Criteria as a wild card is as Criteria2
="*PR*", but this looks for the text PR in the filter and
not the value in the variable PR. Below I have copied the
macro. How can I set the contains Criteria2 in the Auto
Filter statement to use the value in the variable PR and
not the text PR.

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/16/2003 by DavidT
'
' Keyboard Shortcut: Ctrl+a
'
Dim PR
PR = ActiveCell.Value
Sheets("TVA WeTrader Custom Features").Select
Selection.AutoFilter Field:=1, Criteria1:=PR,
Operator:=xlOr, _
Criteria2:="=*PR*"
End Sub
 
Back
Top