ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If then statement in excell? (https://www.excelbanter.com/excel-programming/391043-if-then-statement-excell.html)

BMatson

If then statement in excell?
 
How do I create an If then statement in excell?

Tim Williams

If then statement in excell?
 
If something = True then
'do something
End If

or did you mean in a worksheet formula ?

=IF(A1="Oranges","Fruity","No fruit")

Tim

"BMatson" wrote in message
...
How do I create an If then statement in excell?




JLatham

If then statement in excell?
 
=IF(test condition, true action, false action)
Help on the function will give more details. Here are a couple of examples:
=IF(A1=4, "A1 does equal 4","") shows blank if A1 doesn't = 4.
=IF(A1=A5,(A1+A5)*3,0) ' adds A1+ A5 and multiplies result by 3 if A1=A5,
results is zero if not equal.
=IF(AND(B1=3,X5="Ripe"),"conditions met","conditions not met")

IF statements can be nested, with another IF statement being placed in
either the True or False action portions of each. You can carry this on to a
total of 7 nested functions in pre-2007 versions of Excel.

"BMatson" wrote:

How do I create an If then statement in excell?


JLatham

If then statement in excell?
 
In my previous post I showed how to use the worksheet function IF. Now,
since this is the Programming group, perhaps you're looking for VBA code? In
that case:

Sub Dummy()
IF Range("X1").Value = 4 Then
Range("X2").Value = "X1 is 4" ' or some math or whatever
Range("X3").Value = "I said: X1 is 4!" ' can use multiple statements
End if
End Sub

there is also the IF...Then...Else variation, and the If...Then...ElseIf...
variation. VBA Help has discussions of these.

"BMatson" wrote:

How do I create an If then statement in excell?


JLatham

If then statement in excell?
 
Hit [Enter] too soon!

Sub TestIfThenElse()
IF Range("X1").Value = 4 Then
'code to perform when condition is true
Else
'code to perform when condition is not true
End If

You can have multiple code statements in both the Then section and the Else
section if you need them.

"BMatson" wrote:

How do I create an If then statement in excell?



All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com