The Google Spreadsheet IF function allows you to use decision making in your worksheets.
The IF function tests to see if a certain condition in a spreadsheet cell is true or false.
If the condition is true, the function will carry out a specific operation. If the condition is false, the function will carry out a different operation.
The syntax for the IF function is:
=IF ( test, then_true, otherwise_value )
The function's three arguments are:
test - a value or expression that is tested to see if it is true or false.
then_true - the operation that is carried out if the test is true.
otherwise_value - the operation that is carried out if the test is false.
Note: When entering the IF function, the three arguments are separated by commas ( , ).
Example Using the Google Spreadsheet IF Function:
We will be entering the following IF function in cell A2:
= IF ( A1 < 26 , 100 , 200 )What the function does is test to see if the value in cell A1 is less than 26. If A1 is less than 26, the function displays the number 100 in cell A2. If the value in A1 is greater than 26, the function displays 200 in cell A2.
- Enter 35 into cell A1
- Click on cell A2 - the location where the results will be displayed
- Type the equal sign ( = ) followed by the name of the function if
- As you type, an auto-suggest box appears with the names and syntax of functions that begin with the letter I
- When the name IF appears in at the top of the box, press the Enter key on the keyboard to enter the function name and open round bracket into cell A2
- Click on cell A1 on the spreadsheet to enter that cell reference
- After the cell reference, type the less than symbol ( < ) followed by the number 26
- Enter a comma to complete the test argument
- Type 100 followed by a comma to enter this number as the then_true argument
- Type 200 to enter this number as the otherwise_value argument - do not enter a comma
- Type a closing round bracket " ) " to complete the function's arguments
- Press the ENTER key on the keyboard to complete the function
- The value 200 should appear in cell A2, since the value in A1 is greater than 26
- To change the result in cell A2, change the number in cell A1 to 15 and press the Enter key
- The value 100 should now be present in cell A2 since the value in A1 is now less than 26
- If you click on cell A2, the complete function = IF ( A1 < 26 , 100 , 200 ) appears in the formula bar above the worksheet