if-statementgoogle-sheets

Multiple nested if blocks in google spreadsheets formulas


Im trying to write a nested if statement like this pseudo code :

=IF(h4=1, "CORRECT", IF(h4=2, "CORRECT"), IF(h4=3, "CORRECT"), IF(h4=4, "CORRECT")) 

But im getting the following error, if i write out the code about and add an if statement each time. ie. start with only the first if block and then add more testing each time, it breaks when i add the third statement.

Wrong number of arguments to IF. Expected between 2 and 3 arguments, but received 4 arguments.

Is there a better way to nest if blocks in google spreadsheets ?

Ive made a google spreadsheet of the issue here : https://docs.google.com/spreadsheets/d/1MBOmaTNI5C_spSVudCQPeanHtoFr36kglg9BXUeAZxU/edit#gid=0

(the above code is only an example of nesting IF blocks, not the actual issue im trying to solve)


Solution

  • The error was actually just a simple syntax issue - the placement of your parentheses - here is the correct:

    =IF(H4=1, "CORRECT", IF(H4=2, "CORRECT", IF(H4=3, "CORRECT")))
    

    I also fixed it on your spreadsheet.

    Every if statement must have 3 parts essentially, so if(this, then this, else this) so when nesting, the else this part of the formula is the next condition..

    =IF(h4=1, "CORRECT", IF(h4=2, "CORRECT", IF(h4=3, "CORRECT", IF(h4=4, "CORRECT"))))