EXCEL logical functions : IF function

The IF function, one of many EXCEL logical functions, is used to evaluate a logical condition, passed as an argument to the function.  The function will then return one of two values specified as the second argument or the third argument in the function. It will return the second argument if the test evaluates to TRUE or the third argument if the test evaluates to FALSE.

Syntax

IF(logical test , value if TRUE, value if FALSE)

Logical test:  is a condition that evaluates to TRUE or FALSE.

Value if TRUE : is the value to be returned by the function if  logical test evaluates to TRUE.

Value if FALSE : is the value to be returned by the function if  logical test evaluates to FALSE.

Examples:

A1 = 6

B1 = 10

=IF(A1>5; “Valid value”; “Invalid Value”): returns “Valid value”

=IF(A1>B1;A1-B1;B1-A1) : returns 4. This function will always return a positive number.

Related posts:

  1. Check formula errors in Excel 2007 using IFERROR Function
  2. Nesting the IF function
  3. How to use the INDEX function
  4. How to nest and join multiple functions in a cell
  5. Function to return the address of a lookup value

Comments

  1. Greg says:

    Is there a method in Excel (VBA) to accomplish an IF as follows:

    IF (True)
    then Value
    Else]
    KEEP original Value
    Endif

  2. admin says:

    You don’t need an ELSE clause in this case. Just the IF part. and if the IF test is false your value will remain as is.

    Example:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If a = b Then Target.Value = 123
    End Sub

    If you want to be explicit you can write:

    If a = b Then Target.Value = 123 else Target.Value = Target.Value

    but this is redundant anyhow.

Speak Your Mind

*