Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXCEL SORT CRITERIA AUTOFILTER

Status
Not open for further replies.

fatboyfatter

Technical User
Nov 23, 2008
3
GB
HELP!,
As they say a little knowledge is dangerous, so I need you guys to put me right!
I am trying to automate a filter using macros.
I have set a cell vaue as the FNVARIABLE, this will alwys be an alpha string contained in a title string in a cell
Example 54321A BRKT LH MLDG OTR.
I may wan to find in a list all lines containg BRKT.
I want to use a cell say $A$1 as the input criteria and then autofilter the list blah blah blah!
This is the code I have so far used, when tring to set the autofilter criteria the coding uses an absolute and not the variable I need it to be. when viewing the resultant filter it alwys defaults to "EQUALS" I need it to be "CONTAINS"
Any suggestions?
CODE:
Dim FNVARIABLE
FNVARIABLE = Worksheets("sheet1").Range("A1").Value
Sheets("sheet2)").Select
Columns("c:c").Select
Selection.Copy
Sheets("Sheet3").Select
Range("C1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.AutoFilter Field:=3, Criteria1:=FNVARIABLE, Operator:=xlAnd, _
Criteria2:=FNVARIABLE
 
Hi,

Did you try using your macro recorder to record the CONTAINS operator?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks,
Actually I used the recorder to start with, For info if you look at the Code using all the different criteria, when it comes to the 'contains' statement the code looks like this :- ="=*yourstring*", If I substitute any of the Yourstring with FNVARIABLE, when you run the Macro , the search criteria is absolute:- FNVARIABLE, I cannot find any code to subsitute the above to recognise the Alpha code.
Thanks
Paul F
 
="=*" & FNVARIABLE & "*"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top