How do you write multiple conditions in an IF statement

HowdeeDoodee

Well-known Member
Joined
Nov 15, 2004
Messages
599
I keep trying to decipher what some of you have put into an IF statement but get confused.

For example:

If Condition1 = Condition2 And Condition3 = Condition4 Then insert "Sue Me" in A1 Else insert "IMA NUT" in B1.

If possible, please explain the nesting on the syntax. Thanks in advance.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
HowdeeDoodee said:
I keep trying to decipher what some of you have put into an IF statement but get confused.

For example:

<font color="red">If Condition1 = Condition2 And Condition3 = Condition4 Then insert "Sue Me" in A1 Else insert "IMA NUT" in B1.</font>

If possible, please explain the nesting on the syntax. Thanks in advance.
Hi HowdeeDoodee:

Please clarify whether you mean ...

in cell A1

=IF(
Condition1=TRUE,IF(
Condition2=TRUE,IF(
Condition3=TRUE,IF(
Condition4=TRUE,
"SueMe",
"IMA Nut"))))

and then let us take it from there!
 
Upvote 0
Thanks Yogi.

I just would like some sample code for various options like equal to, greater than, less than, AND, OR, NOT ect. and so on. Enough samples and I can figure out how to code the IF statements on my own. From your example I can see how the bracketing works.
 
Upvote 0
HowdeeDoodee said:
Thanks Yogi.

I just would like some sample code for various options like equal to, greater than, less than, AND, OR, NOT ect. and so on. Enough samples and I can figure out how to code the IF statements on my own. From your example I can see how the bracketing works.
Hi HowdeeDoodee:

I think you have enough information to get started using the IF function. Start with a single condition IF formulation, and then build up to include multiple conditions. But it is essential that you get over the hesitation and actually DO IT!
 
Upvote 0
If you're referring to VBA code then:-

Code:
Sub Test()
    If condition1 = condition2 And condition3 = condition4 Then
        [A1] = "Sue Me"
    Else
        [B1] = "IMA NUT"
    End If
End Sub
 
Upvote 0
I just would like some sample code for various options like equal to, greater than, less than, AND, OR, NOT ect. and so on. Enough samples and I can figure out how to code the IF statements on my own.

From memory I think that my early problem was the difference in syntax between formulae written in a cell and that written in code. The basic is that a conditional element comes first in the worksheet. e.g. In cell A1
Code:
=IF(AND(B1=C1,D1<>""),"Yes","No")
this would be written as
Code:
    If [B1] = [C1] And [D1] <> "" Then
        [A1] = "Yes"
    Else: [A1] = "No"
    End If
HTH (y)
 
Upvote 0
Thank you for the response. Do you write an OR statement the same way you write the AND statement? Do you merely substittute the word OR for AND? Also, how would you combine OR and AND in the same statement?
 
Upvote 0
Sub test()
If ([A1] = [D1] And [E1] = [F1]) Or [G1] = 7 Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub
 
Upvote 0
see if this helps;
http://personal-computer-tutor.com/if2.htm

HowdeeDoodee said:
I keep trying to decipher what some of you have put into an IF statement but get confused.

For example:

If Condition1 = Condition2 And Condition3 = Condition4 Then insert "Sue Me" in A1 Else insert "IMA NUT" in B1.

If possible, please explain the nesting on the syntax. Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,215,569
Messages
6,125,600
Members
449,238
Latest member
wcbyers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top