Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Test if a Cell contains either of 12 different words

I'm trying to test if a cell contains any of 12 different words (note the
words may be embedded in a phrase). Is there an easier way than to write 12
if statements?

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Test if a Cell contains either of 12 different words

Hi Joy

Try the Select Case statement

Not sure how to test with embedded text though - something for me to play
with and find out

HTH

"J@Y" wrote:

I'm trying to test if a cell contains any of 12 different words (note the
words may be embedded in a phrase). Is there an easier way than to write 12
if statements?

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Test if a Cell contains either of 12 different words

The embedded text is what I'm having trouble with ... I tried using "*text*"
with Select Case and it doesnt work, the * are recognized literally as *.

"steve_doc" wrote:

Hi Joy

Try the Select Case statement

Not sure how to test with embedded text though - something for me to play
with and find out

HTH

"J@Y" wrote:

I'm trying to test if a cell contains any of 12 different words (note the
words may be embedded in a phrase). Is there an easier way than to write 12
if statements?

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Test if a Cell contains either of 12 different words

if instr(1,cell.value,"abc",vbTextcompare) 0 then
' contained in cell

--
Regards,
Tom Ogilvy



"J@Y" wrote:

The embedded text is what I'm having trouble with ... I tried using "*text*"
with Select Case and it doesnt work, the * are recognized literally as *.

"steve_doc" wrote:

Hi Joy

Try the Select Case statement

Not sure how to test with embedded text though - something for me to play
with and find out

HTH

"J@Y" wrote:

I'm trying to test if a cell contains any of 12 different words (note the
words may be embedded in a phrase). Is there an easier way than to write 12
if statements?

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Test if a Cell contains either of 12 different words

In a worksheet, you can use something like:

=SUM(COUNTIF(B2,{"*APPLE*","*BUT*","*CAR*","*DAM*" ,"*EXCEL*","*FOR*","*GO*","*HI*","*AND*","*THE*"," *DOG*","*OR*"}))

this could be adapted to code as well.

Demo'd from the immediate window:

?
Evaluate("SUM(COUNTIF(B2,{""*APPLE*"",""*BUT*"","" *CAR*"",""*DAM*"",""*EXCEL*"",""*FOR*"",""*GO*""," "*HI*"",""*AND*"",""*THE*"",""*DOG*"",""*OR*""}))" )
4
? Range("B2").Value
Go for an apple


--
Regards,
Tom Ogilvy


"J@Y" wrote:

The embedded text is what I'm having trouble with ... I tried using "*text*"
with Select Case and it doesnt work, the * are recognized literally as *.

"steve_doc" wrote:

Hi Joy

Try the Select Case statement

Not sure how to test with embedded text though - something for me to play
with and find out

HTH

"J@Y" wrote:

I'm trying to test if a cell contains any of 12 different words (note the
words may be embedded in a phrase). Is there an easier way than to write 12
if statements?

Thanks.



  #6   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Test if a Cell contains either of 12 different words

What exactly does the evaluate do?

"Tom Ogilvy" wrote:

In a worksheet, you can use something like:

=SUM(COUNTIF(B2,{"*APPLE*","*BUT*","*CAR*","*DAM*" ,"*EXCEL*","*FOR*","*GO*","*HI*","*AND*","*THE*"," *DOG*","*OR*"}))

this could be adapted to code as well.

Demo'd from the immediate window:

?
Evaluate("SUM(COUNTIF(B2,{""*APPLE*"",""*BUT*"","" *CAR*"",""*DAM*"",""*EXCEL*"",""*FOR*"",""*GO*""," "*HI*"",""*AND*"",""*THE*"",""*DOG*"",""*OR*""}))" )
4
? Range("B2").Value
Go for an apple


--
Regards,
Tom Ogilvy


"J@Y" wrote:

The embedded text is what I'm having trouble with ... I tried using "*text*"
with Select Case and it doesnt work, the * are recognized literally as *.

"steve_doc" wrote:

Hi Joy

Try the Select Case statement

Not sure how to test with embedded text though - something for me to play
with and find out

HTH

"J@Y" wrote:

I'm trying to test if a cell contains any of 12 different words (note the
words may be embedded in a phrase). Is there an easier way than to write 12
if statements?

Thanks.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Test if a Cell contains either of 12 different words

It evaluates the string passed to it as if it was entered in a cell in the
worksheet.

--
Regards,
Tom Ogilvy


"J@Y" wrote:

What exactly does the evaluate do?

"Tom Ogilvy" wrote:

In a worksheet, you can use something like:

=SUM(COUNTIF(B2,{"*APPLE*","*BUT*","*CAR*","*DAM*" ,"*EXCEL*","*FOR*","*GO*","*HI*","*AND*","*THE*"," *DOG*","*OR*"}))

this could be adapted to code as well.

Demo'd from the immediate window:

?
Evaluate("SUM(COUNTIF(B2,{""*APPLE*"",""*BUT*"","" *CAR*"",""*DAM*"",""*EXCEL*"",""*FOR*"",""*GO*""," "*HI*"",""*AND*"",""*THE*"",""*DOG*"",""*OR*""}))" )
4
? Range("B2").Value
Go for an apple


--
Regards,
Tom Ogilvy


"J@Y" wrote:

The embedded text is what I'm having trouble with ... I tried using "*text*"
with Select Case and it doesnt work, the * are recognized literally as *.

"steve_doc" wrote:

Hi Joy

Try the Select Case statement

Not sure how to test with embedded text though - something for me to play
with and find out

HTH

"J@Y" wrote:

I'm trying to test if a cell contains any of 12 different words (note the
words may be embedded in a phrase). Is there an easier way than to write 12
if statements?

Thanks.

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
how to copy the first word or two words from a cell containing a complete sentence to another cell jonny Excel Discussion (Misc queries) 7 May 19th 23 03:43 AM
Swapping two words in a cell and placing them in another cell Christie Excel Worksheet Functions 1 February 12th 09 12:42 AM
counting occurrence of specific words in another group of words [email protected] Excel Programming 0 August 5th 06 03:43 AM
Calculate mean of test scores from rows of test answers RiotLoadTime Excel Discussion (Misc queries) 1 July 26th 06 05:14 PM
How can i test a cell for bold style in a cell (Excel 2003)? Mike A. Excel Worksheet Functions 2 March 6th 06 07:23 PM


All times are GMT +1. The time now is 11:54 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"