Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Find part of a word in Advanced Filter Code

I sent this originally to the worksheet funtions newsgroup but then
realised that it is probably more of a programming issue than a funtions
issue. So sorry for the double post...

I'm trying to get an advanced filter to work so that it will bring back
all records
with part of the word rather than just the start of a word. This works
very well when I use AutoFilter with the "Contains" criteria. But when I
do an advanced filter, only records that start with the word get filtered.

I have something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$2" Or _
Target.Address = "$B$2" Then
Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
Unique:=False
End If
End Sub

This is code when you right click the tab. I tried putting "*" in various
places in
this code but can't get it to work. The only way is to put a "*" before
any word I'd
like to search for in the B2 or A2 cell. This works, but I'd like to be
able have it do it automatically so that I just have to type the word I'm
looking for without any "*"'s.

Thanks..
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Find part of a word in Advanced Filter Code

You need to add a criteria range to your advanced filter statement. For example:

Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("E3:E4"), _
Unique:=False

Where the value in E3 is the appropriate column heading, and E4 has a string like *WordYouWant* -
which is the corrollary of autofilter's "Contains"

HTH,
Bernie
MS Excel MVP


"Sierras" wrote in message
...
I sent this originally to the worksheet funtions newsgroup but then realised that it is probably
more of a programming issue than a funtions issue. So sorry for the double post...

I'm trying to get an advanced filter to work so that it will bring back all records
with part of the word rather than just the start of a word. This works very well when I use
AutoFilter with the "Contains" criteria. But when I do an advanced filter, only records that
start with the word get filtered.

I have something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$2" Or _
Target.Address = "$B$2" Then
Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
Unique:=False
End If
End Sub

This is code when you right click the tab. I tried putting "*" in various places in
this code but can't get it to work. The only way is to put a "*" before any word I'd
like to search for in the B2 or A2 cell. This works, but I'd like to be able have it do it
automatically so that I just have to type the word I'm looking for without any "*"'s.

Thanks..



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Find part of a word in Advanced Filter Code

And if you want to have flexibility in choosing the word, you could start with code like

Range("E4").Value = "*" & InputBox("Word to look for") & "*"

HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
You need to add a criteria range to your advanced filter statement. For example:

Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("E3:E4"), _
Unique:=False

Where the value in E3 is the appropriate column heading, and E4 has a string like *WordYouWant* -
which is the corrollary of autofilter's "Contains"

HTH,
Bernie
MS Excel MVP


"Sierras" wrote in message
...
I sent this originally to the worksheet funtions newsgroup but then realised that it is probably
more of a programming issue than a funtions issue. So sorry for the double post...

I'm trying to get an advanced filter to work so that it will bring back all records
with part of the word rather than just the start of a word. This works very well when I use
AutoFilter with the "Contains" criteria. But when I do an advanced filter, only records that
start with the word get filtered.

I have something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$2" Or _
Target.Address = "$B$2" Then
Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
Unique:=False
End If
End Sub

This is code when you right click the tab. I tried putting "*" in various places in
this code but can't get it to work. The only way is to put a "*" before any word I'd
like to search for in the B2 or A2 cell. This works, but I'd like to be able have it do it
automatically so that I just have to type the word I'm looking for without any "*"'s.

Thanks..





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Find part of a word in Advanced Filter Code

On Fri, 10 Mar 2006 12:44:37 -0500, Bernie Deitrick <deitbe consumer dot
org wrote:

Range("E4").Value = "*" & InputBox("Word to look for") & "*"


Seems to work the same with or without the criteria range. Now I have
this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$2" Or _
Target.Address = "$B$2" Then
Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("B1:B2"), _
Unique:=False
End If
End Sub

The line suggested Range("E2").Value = "*" & InputBox("Word to look for")
& "*"
creates a circular that I have to hit Ctrl - Break to get out of. I don't
know where to put this line in order to make it work. In any case, it
would be nicer to be able to just put the word that I'd like to search for
in B2 and have the code put in the *'s before and after without a command
box.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Find part of a word in Advanced Filter Code

Use this, and type your desired words into either A2 or B2. This assumes that your criteria are
entered into A1:B2 - headers in A1 and B1, and values in A2 and B2.

HTH,
Bernie
MS Excel MVP


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$2" Or _
Target.Address = "$B$2" Then
Application.EnableEvents = False

Target.Value = "*" & Target.Value & "*"

Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("A1:B2"), _
Unique:=False
Application.EnableEvents = True
End If
End Sub

"Sierras" wrote in message
...
On Fri, 10 Mar 2006 12:44:37 -0500, Bernie Deitrick <deitbe consumer dot org wrote:

Range("E4").Value = "*" & InputBox("Word to look for") & "*"


Seems to work the same with or without the criteria range. Now I have this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$2" Or _
Target.Address = "$B$2" Then
Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("B1:B2"), _
Unique:=False
End If
End Sub

The line suggested Range("E2").Value = "*" & InputBox("Word to look for") & "*"
creates a circular that I have to hit Ctrl - Break to get out of. I don't know where to put this
line in order to make it work. In any case, it would be nicer to be able to just put the word
that I'd like to search for in B2 and have the code put in the *'s before and after without a
command box.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Find part of a word in Advanced Filter Code

Thank you very much for your time. This is working just as I wanted.

Regards,

Sierras

On Fri, 10 Mar 2006 14:29:50 -0500, Bernie Deitrick <deitbe consumer dot
org wrote:

Use this, and type your desired words into either A2 or B2. This
assumes that your criteria are
entered into A1:B2 - headers in A1 and B1, and values in A2 and B2.

HTH,
Bernie
MS Excel MVP


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$2" Or _
Target.Address = "$B$2" Then
Application.EnableEvents = False

Target.Value = "*" & Target.Value & "*"

Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("A1:B2"), _
Unique:=False
Application.EnableEvents = True
End If
End Sub

"Sierras" wrote in message
...
On Fri, 10 Mar 2006 12:44:37 -0500, Bernie Deitrick <deitbe consumer
dot org wrote:

Range("E4").Value = "*" & InputBox("Word to look for") & "*"


Seems to work the same with or without the criteria range. Now I have
this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$2" Or _
Target.Address = "$B$2" Then
Range("Database").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("B1:B2"), _
Unique:=False
End If
End Sub

The line suggested Range("E2").Value = "*" & InputBox("Word to look
for") & "*"
creates a circular that I have to hit Ctrl - Break to get out of. I
don't know where to put this
line in order to make it work. In any case, it would be nicer to be
able to just put the word
that I'd like to search for in B2 and have the code put in the *'s
before and after without a
command box.






--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
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
Find blank with Advanced Filter CJ Excel Discussion (Misc queries) 2 December 16th 08 10:46 PM
Code to replace Advanced Filter RobN[_2_] Excel Discussion (Misc queries) 4 June 14th 07 12:31 PM
Advanced Filter contains part of a word Sierras Excel Worksheet Functions 3 March 8th 06 08:20 PM
Find part of a word in cell Elaine Excel Discussion (Misc queries) 7 March 3rd 06 07:37 PM
Problems implementing advanced filter code... jarviscars Excel Programming 7 January 5th 06 03:06 PM


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

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

About Us

"It's about Microsoft Excel"