Operating System - Microsoft
1751972 Members
4995 Online
108784 Solutions
New Discussion юеВ

Re: several condition in Excel

 
Nicolas Dumeige
Esteemed Contributor

several condition in Excel

Hello,

I'm really dumb with Excel. How do write the equivalent of this in Excel :

if (cell=value1) or (cell=value2) or (cell=value3)
then cell2=new_value
else cell2=default_value

Thanks
All different, all Unix
7 REPLIES 7
Bruno Ganino
Honored Contributor

Re: several condition in Excel

Microsoft explains the syntax of the IF function thusly:

=IF(logical_test,value_if_true,value_if_false)

What that means, simply put, is this:

=IF("if the condition stated here is true", then enter "this value, else enter "this value")

A practical example would be a spreadsheet containing exam marks for students. Perhaps you wanted to see at a glance who had failed and who had passed. An IF function would be perfect for this. Let's assume the marks are in column B, starting from row 4. Our formula would look like this:

=IF(B4>50, "Pass", "Fail")

Torino (Turin) +2H
Ganesh Babu
Honored Contributor

Re: several condition in Excel

HEre it is

Copy the below formula to Cell2 (in your question). I have assumed that cell = A2 in my formula.. u can change it to your actual cell number..


=IF(OR(A2=1,A2=2,A2=3),4,0)


Ganesh
Ganesh Babu
Honored Contributor

Re: several condition in Excel

Also i have assumed

value1=1
value2=2
value3=3
new_value=4
default_value=0

Just in case u need a different value.. u can change in the formula..

Ganesh
Bruno Ganino
Honored Contributor

Re: several condition in Excel

If function Can be Nested up to 7 times.

Nested IF functions are a simple way to do a complex conditional formula. Nested IF functions allow you to use up to seven IF functions to impose conditions.

Essentially, the way a nested if statement would work is like this:

=IF("if this condition stated here is true", then enter "this value, else if("if this condition stated here is true", then enter "this value, else enter"this value"))

HTH
Bruno


Torino (Turin) +2H
Nicolas Dumeige
Esteemed Contributor

Re: several condition in Excel

Thanks for your help.

So there are no instruction like case or switch in the Excel syntax ?

Another question, the && and || operator cannot be used ?

Nicolas
All different, all Unix
Ganesh Babu
Honored Contributor

Re: several condition in Excel

u can use case or switch statement in the macros or VBA programming not in excel forumla.

&& and || cannot be used in excel

Ganesh
Bruno Ganino
Honored Contributor

Re: several condition in Excel

Hi
If you know like behavior, you can also define of the functions personalized.
Bruno
Torino (Turin) +2H