PC Review


Reply
Thread Tools Rate Thread

Autofilter - Contains

 
 
al
Guest
Posts: n/a
 
      25th Mar 2009
I'm trying to use macro below to find text in a filtered column using
macro below - it's not working when i input an existing text in the
input box - can someone pls correct my macro - thxs

Sub Macro()
'
'
txt = InputBox("Enter text to find")
'
Selection.AutoFilter Field:=3, Criteria1:="=*txt*",
Operator:=xlAnd
End Sub
 
Reply With Quote
 
 
 
 
FSt1
Guest
Posts: n/a
 
      25th Mar 2009
hi
what do you do to the sheet before you put text into the input box?
are you high lighting any section of the sheet?
this macro is trying to filter a high lighted section of the sheet that you
say is already filtered.
what do you want it to do?

Regards
FSt1

"al" wrote:

> I'm trying to use macro below to find text in a filtered column using
> macro below - it's not working when i input an existing text in the
> input box - can someone pls correct my macro - thxs
>
> Sub Macro()
> '
> '
> txt = InputBox("Enter text to find")
> '
> Selection.AutoFilter Field:=3, Criteria1:="=*txt*",
> Operator:=xlAnd
> End Sub
>

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      25th Mar 2009
Hi

The variable txt should not be in double quotes. The wild card string *
should be in quotes as mentioned below. Also from your code we dont get which
range you have selected. Please try the below.

txt = InputBox("Enter text to find")
Range("C1").AutoFilter field:=3, Criteria1:="*" & txt & "*"

If this post helps click Yes
--------------
Jacob Skaria

"al" wrote:

> I'm trying to use macro below to find text in a filtered column using
> macro below - it's not working when i input an existing text in the
> input box - can someone pls correct my macro - thxs
>
> Sub Macro()
> '
> '
> txt = InputBox("Enter text to find")
> '
> Selection.AutoFilter Field:=3, Criteria1:="=*txt*",
> Operator:=xlAnd
> End Sub
>

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      25th Mar 2009
A more generic way of doing this is to simply use AutoFilter.Range

Dim txt As String

txt = InputBox("Enter text to find")

txt = "*" & txt & "*"

With ActiveSheet
.AutoFilter.Range.AutoFilter Field:=3, Criteria1:=txt
End With

or you can do it the following way. The advantage of this way is that the
worksheet with the AutoFilter does not have to be the ActiveSheet.

With Sheets("Sheet1")
.AutoFilter.Range.AutoFilter Field:=3, Criteria1:=txt
End With

It does not matter whether you concatenate the asterisks before the
AutoFilter code as I have done or as Jacob did it in his example. I just did
it that way to demonstrate an alternative.

Regards,

OssieMac



"Jacob Skaria" <(E-Mail Removed)> wrote in message
news:5A5FBE63-7A24-49EA-9C97-(E-Mail Removed)...
> Hi
>
> The variable txt should not be in double quotes. The wild card string *
> should be in quotes as mentioned below. Also from your code we dont get
> which
> range you have selected. Please try the below.
>
> txt = InputBox("Enter text to find")
> Range("C1").AutoFilter field:=3, Criteria1:="*" & txt & "*"
>
> If this post helps click Yes
> --------------
> Jacob Skaria
>
> "al" wrote:
>
>> I'm trying to use macro below to find text in a filtered column using
>> macro below - it's not working when i input an existing text in the
>> input box - can someone pls correct my macro - thxs
>>
>> Sub Macro()
>> '
>> '
>> txt = InputBox("Enter text to find")
>> '
>> Selection.AutoFilter Field:=3, Criteria1:="=*txt*",
>> Operator:=xlAnd
>> End Sub
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel 2007 autofilter change to 2003 autofilter functionality? jonnybrovo815 Microsoft Excel Misc 1 19th Apr 2010 10:05 PM
2007 excel autofilter back to 2003 autofilter? jonnybrovo815 Microsoft Excel Misc 3 19th Apr 2010 08:11 PM
2007 excel autofilter change back to 2003 autofilter? jonnybrovo815 Microsoft Excel Misc 1 19th Apr 2010 05:53 PM
2007 Autofilter worse than 2003 Autofilter =?Utf-8?B?anNreQ==?= Microsoft Excel Misc 9 31st Oct 2007 12:14 AM
How to Sort within AutoFilter with Protection on (and AutoFilter . =?Utf-8?B?Z2libG9u?= Microsoft Excel Misc 1 16th Feb 2006 12:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 AM.