Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Multiple Logical Tests in IF function

dear members,

I want to perform multiple logical test in the IF function, how can i do that.
IF function takes only single logical test. for example :

IF DEPT1=COMPUTERS THEN FIRST ELSE NONE,
IF DEPT1=ENGLISH THEN SECOND ELSE NONE,
IF DEPT1=SCIENCE THEN THIRD ELSE NONE ....... and so on......

as u can see above the IF function should take multiple arguments and
according to the condition should display the result. IF function in excel
only takes one argument .

could any one help me out in this. Is there any function in excel which
takes multiple logical tests.

thanks
regards
sandeep

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Multiple Logical Tests in IF function

Since you are posting in the programming section I assume you are writing
code. That being the case you probably want a Select Case statement...
something like this...

Select Case DEPT1
Case "COMPUTERS"
msgbox "COMPUTERS"
Case "ENGLISH"
msgbox "ENGLISH"
Case "SCIENCE"
msgbox "SCIENCE"
Case Else
msgbox "How did I get here???"
end Select
--
HTH...

Jim Thomlinson


"sandeep" wrote:

dear members,

I want to perform multiple logical test in the IF function, how can i do that.
IF function takes only single logical test. for example :

IF DEPT1=COMPUTERS THEN FIRST ELSE NONE,
IF DEPT1=ENGLISH THEN SECOND ELSE NONE,
IF DEPT1=SCIENCE THEN THIRD ELSE NONE ....... and so on......

as u can see above the IF function should take multiple arguments and
according to the condition should display the result. IF function in excel
only takes one argument .

could any one help me out in this. Is there any function in excel which
takes multiple logical tests.

thanks
regards
sandeep

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Multiple Logical Tests in IF function

=VLOOKUP(DEPT1,{"Computers","First";"English","Sec ond";"Science","Third"},2,
False)

extend as required

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"sandeep" wrote in message
...
dear members,

I want to perform multiple logical test in the IF function, how can i do

that.
IF function takes only single logical test. for example :

IF DEPT1=COMPUTERS THEN FIRST ELSE NONE,
IF DEPT1=ENGLISH THEN SECOND ELSE NONE,
IF DEPT1=SCIENCE THEN THIRD ELSE NONE ....... and so on......

as u can see above the IF function should take multiple arguments and
according to the condition should display the result. IF function in

excel
only takes one argument .

could any one help me out in this. Is there any function in excel which
takes multiple logical tests.

thanks
regards
sandeep



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Multiple Logical Tests in IF function

sandeep,

if you are trying to come up with a formula for a cell, use nested IF functions like this:

=IF(A1="Computers","First",IF(A1="English","Second ",IF(A1="Science","Third","")))

now I don't know if there is a limit on how many nested IF functions you can have. Someone else might know.




If you need code for VBA, you can do it like this:

If DEPT1 = "Computers" Then
"First" '<--- Probably want to set a string variable to "First"
Else If DEPT1 = "English" Then
"Second"
Else If DEPT1 = "Science" Then
"Third"
Else
""
End If

That will to the same thing as the SELECT CASE statement that Jim Thomlinson posted.

I hope this helps,

Conan Kelly




"sandeep" wrote in message ...
dear members,

I want to perform multiple logical test in the IF function, how can i do that.
IF function takes only single logical test. for example :

IF DEPT1=COMPUTERS THEN FIRST ELSE NONE,
IF DEPT1=ENGLISH THEN SECOND ELSE NONE,
IF DEPT1=SCIENCE THEN THIRD ELSE NONE ....... and so on......

as u can see above the IF function should take multiple arguments and
according to the condition should display the result. IF function in excel
only takes one argument .

could any one help me out in this. Is there any function in excel which
takes multiple logical tests.

thanks
regards
sandeep



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Multiple Logical Tests in IF function

The limit is 7. You can get around it but it is a bit of work... Check out
this link...

http://www.cpearson.com/excel/nested.htm
--
HTH...

Jim Thomlinson


"Conan Kelly" wrote:

sandeep,

if you are trying to come up with a formula for a cell, use nested IF functions like this:

=IF(A1="Computers","First",IF(A1="English","Second ",IF(A1="Science","Third","")))

now I don't know if there is a limit on how many nested IF functions you can have. Someone else might know.




If you need code for VBA, you can do it like this:

If DEPT1 = "Computers" Then
"First" '<--- Probably want to set a string variable to "First"
Else If DEPT1 = "English" Then
"Second"
Else If DEPT1 = "Science" Then
"Third"
Else
""
End If

That will to the same thing as the SELECT CASE statement that Jim Thomlinson posted.

I hope this helps,

Conan Kelly




"sandeep" wrote in message ...
dear members,

I want to perform multiple logical test in the IF function, how can i do that.
IF function takes only single logical test. for example :

IF DEPT1=COMPUTERS THEN FIRST ELSE NONE,
IF DEPT1=ENGLISH THEN SECOND ELSE NONE,
IF DEPT1=SCIENCE THEN THIRD ELSE NONE ....... and so on......

as u can see above the IF function should take multiple arguments and
according to the condition should display the result. IF function in excel
only takes one argument .

could any one help me out in this. Is there any function in excel which
takes multiple logical tests.

thanks
regards
sandeep






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
Logical function with multiple cells Demosthenes Excel Worksheet Functions 6 May 8th 10 02:20 AM
How do I create an IF formula with 2 logical tests FSt1 Excel Discussion (Misc queries) 0 June 16th 09 06:50 AM
How Can i use the cell colors as logical tests? kashof Excel Worksheet Functions 2 January 15th 08 08:41 PM
Average a group of tests for grade, some tests not taken by all. Scafidel Excel Discussion (Misc queries) 4 August 19th 05 03:50 AM
Logical Function - Multiple IF statements vnsrod2000 Excel Worksheet Functions 7 February 4th 05 10:42 PM


All times are GMT +1. The time now is 09:40 PM.

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"