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.
Example Using the Google Spreadsheet IF Function:
Note: For help with this example, see the image above.
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.
- Click on Insert > Formula > More Formulas in the menus to bring up the Insert a formula dialog box.
- Click on Logical in the left hand side of the dialog box to show the list available logical functions.
- Double click on the word IF in the right hand side to enter the IF function into cell A2 in the spreadsheet.
- Close the function dialog box by clicking on the close button in the top right corner of the dialog box.
- Double click on the word test in the function in cell A2 to highlight it.
- Click on cell A1 on the spreadsheet to enter that cell reference into the function.
- After the cell reference, type the less than symbol ( < ) and then the number 26.
- Drag select the then_true argument in the function in A2 to highlight it.
- When doing this Do Not highlight the commas that separate the arguments. They must not be removed or the function will give you an error message.
- Type 100 to enter this number as the then_true argument.
- Drag select on the otherwise_value argument in the function in A2 to highlight it.
- Type 200 to enter this number as the otherwise_value argument.
- 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.