Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Steve
 
Posts: n/a
Default Testing for Multiple Conditions

If I have a string variable, a, and I want to test it for a variety of
things, is there an easy way to do it? I've tried if (a = or("this", "that",
"etc")). That didn't work. I've tried if (a="this" or "that" or "etc") and
that didn't work. Of course if a="this" or a="that" or a="etc" works but if
I have a whole list to test I wonder if there's an easier way. Thanks.
  #2   Report Post  
Trevor Shuttleworth
 
Posts: n/a
Default

Steve

maybe you could put your variables in a list in a worksheet somewhere and
use VLOOKUP ?

For example:

=IF(ISNA(VLOOKUP(A1, LookupRange,1,FALSE)),"not found","found")

Where LookupRange contains a list of "this", "that" and the "other", "etc"

Regards

Trevor


"Steve" wrote in message
...
If I have a string variable, a, and I want to test it for a variety of
things, is there an easy way to do it? I've tried if (a = or("this",
"that",
"etc")). That didn't work. I've tried if (a="this" or "that" or "etc")
and
that didn't work. Of course if a="this" or a="that" or a="etc" works but
if
I have a whole list to test I wonder if there's an easier way. Thanks.



  #3   Report Post  
David McRitchie
 
Posts: n/a
Default

VLOOKUP looks like a better solution, since it is easily expanded but
getting back to the original not working.

You seem to have a mixture of macro and worksheet terminology
and syntax.

Excel:
=OR(A1="this", "that", "etc")
which returns True or False

=IF(OR(A1="this", "that", "etc"), "found", "not found")

the test is on the entire content of a cell and the test is not
case sensitive.

VBA: (case sensitive)
dim val as string, cell as range
val = LCASE(cell.value)
if val = "this" or val = "that" or val = "etc" then
msgbox "Found"
else
msgbox "not found"
end if

HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Trevor Shuttleworth" wrote in message ...
Steve

maybe you could put your variables in a list in a worksheet somewhere and
use VLOOKUP ?

For example:

=IF(ISNA(VLOOKUP(A1, LookupRange,1,FALSE)),"not found","found")

Where LookupRange contains a list of "this", "that" and the "other", "etc"

Regards

Trevor


"Steve" wrote in message
...
If I have a string variable, a, and I want to test it for a variety of
things, is there an easy way to do it? I've tried if (a = or("this",
"that",
"etc")). That didn't work. I've tried if (a="this" or "that" or "etc")
and
that didn't work. Of course if a="this" or a="that" or a="etc" works but
if
I have a whole list to test I wonder if there's an easier way. 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
Add cells from a range based on 2 conditions from 2 other ranges Kelly Excel Worksheet Functions 3 July 7th 05 07:40 PM
SUM based on multiple conditions - SORRY, URGENT!!! marika1981 Excel Worksheet Functions 4 February 18th 05 11:13 AM
should be possible to add more conditions to conditional formatti. excel_jan Excel Discussion (Misc queries) 3 February 9th 05 06:41 PM
How to multiple conditions to validate more than 2 conditions to . Bhuvana Govind Excel Worksheet Functions 1 January 28th 05 07:07 PM
average on 2 conditions Ted Metro Excel Worksheet Functions 6 January 7th 05 08:23 PM


All times are GMT +1. The time now is 08:50 AM.

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

About Us

"It's about Microsoft Excel"