Search notes:

Excel function: IF

=if(condition, value-true, value-false) behaves like a ternary operator: it checks if the first argument is true and evaluates to either the second (if true) or third argument (if false).

Notify user if two cells have different values

A common use case for if is to compare the data that is stored in two cells. The following formula evaluates to Values are different if the values in the cell F1 is different from the value in cell F2. If they're equal, the formula evaluates to an empty string.
=IF(F1<>F2; "Values are different"; "")

Eliminate outliers

With if, it's possible to eliminate outliers. This is demonstrated in the following example.
testData() fills a few values into the first column and adds an average below the values.
removeOutliers() uses if(…) to check if the value in the cell to the left is greater than 100 in which case it is eliminated. It also adds an average for the values.
option explicit

sub main() ' {

    testData
    removeOutliers

end sub ' }

sub testData() ' {

    cells(1, 1) =  28.6
    cells(2, 1) =  57.8
    cells(3, 1) =  53.6
    cells(4, 1) =  32.3
    cells(5, 1) = 123.9 ' Outlier!
    cells(6, 1) =  45.1
    cells(7, 1) =  30.4

    cells(9, 1).formulaR1C1 = "=average(r1c1:r7c1)"

end sub ' }

sub removeOutliers() ' {

    range(cells(1, 2), cells(7, 2)).formulaR1C1 = "=if(rc[-1]>100, """", rc[-1])"

    cells(9, 2).formulaR1C1 = "=average(r1c2:r7c2)"

end sub ' }
Github repository about-Excel, path: /functions/if/eliminate-outliers.bas
This is produced by running main():

See also

Excel functions

Index