Excel Digest

  Excel help for the rest of us

02 Jan

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.

Print This Post Print This Post

Possibly Related Posts (automatically generated)

   
EXCEL logical functions : the NOT function 
EXCEL logical functions : the OR function 
EXCEL logical functions : the AND function 

2 Responses to “EXCEL logical functions : IF function”

  1. 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. 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.

Leave a Reply

© 2010 Excel Digest | Entries (RSS) and Comments (RSS)

GPS Reviews and news from GPS Gazettewordpress logo