View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default variant criteria name to filter

I went back to you r old posting to ss if there was a better discriptyion of
what you wanted. I found this posting

http://www.microsoft.com/office/comm...8-6ae2863b7606

the reason I went back was this line in your latest posting

If LCase(Left(wks.Name, 3)) Like "sum" Then

The "sum" didn't make sense. A like requires a wildcard "*" and the line
above doesn't have the "*". the "*" say any characters foloowing the "sum".
I think you need the following

If LCase(Left(wks.Name, 3)) Like "sum*" Then

Not sure if this will solve all you problems, but it is a start. this says
any string starting with "sum". Now if "sum" isn't at the beginning of the
string then you may need to use this

If LCase(Left(wks.Name, 3)) Like "*sum*" Then

If you sum sometimes have upper and lower case leeters (like previous
posting then this might work

If LCase(Left(wks.Name, 3)) Like "*[sS][uU][mM]*" Then

"Steve" wrote:

morning all.
I received a filter macro from here last October, 2008. Over the past 11
months or so, I've been modifying it as needed to meet various needs, and up
until now, all of my mod's have worked great.
I know I posted on this previously, but it was never answered due to my not
understanding what I was trying to explain.
The filter tool in excel looks for a specific statement based on the
criteria selected.
For my need, there are times when I want to look at a name that's LIKE the
criteria-- but not necessary the same, EXACTLY spelled name. Say, there are
names that are missing periods, for middle initials, or the date in one use
is configured mm/dd/yy, and another is mm/dd/yyyy, or Month-Day-Year, or
have an ampersand instead of and, etc.....
Presently, my filter ignores those-- as it should, I suppose-- and if it
can't find the exact match, there is no match.

My code is:

Sub FilterA()

Dim wks As Worksheet

mv = Range("f2").End(xlDown).value
' this sets the criteria for the ChgAppl#.

mv1 = Range("a2").End(xlDown).value
'this is my add-on to set a second criteria filter- Name of owner.

For Each wks In ActiveWorkbook.Worksheets

If LCase(Left(wks.Name, 3)) Like "sum" Then

With wks
Sheets(wks.Name).Range("A8:F8").AutoFilter field:=1, Criteria1:=mv
'this takes in to acct the chg appl# for a filter.


Sheets(wks.Name).Range("A8:F8").AutoFilter field:=3,
Criteria1:=mv1
'this takes in to account the owner name for a filter.
End With

End If

Next wks
End Sub

My goal would be to do something like--
if mv1 like field then
...........
end if

I've tried a few ideas I had, and none of them worked. And it's been several
weeks since I tried them, so I can't remember specifics at this point.

Thank you for your helps.
Best.