Wrong Number of Arguments to IF in Google Sheets
The 'got N' count in a wrong number of arguments to IF error shows whether a parenthesis closed too late or too early in Google Sheets.
本文目錄
The break-count formula shows #N/A, and the message is: “Wrong number of arguments to IF. Expected between 2 and 3 arguments, but got 1 arguments.” On a different formula, that last number is 4, or 6.
The number tells you where to look. If Sheets counted one argument, a comma that belongs to IF is still inside AND or OR. If it counted four or more, a nested IF closed too early and left an extra value on the outer IF.
Here is the shift log used throughout. Enter the headers in A1:C1 and the eight rows in A2:C9, and leave the Breaks column empty for now:
| Employee | Hours worked | Breaks |
|---|---|---|
| Maya | 3 | |
| Daniel | 4.5 | |
| Priya | 5 | |
| Lucas | 6 | |
| Sofia | 7.5 | |
| Ethan | 8 | |
| Olivia | 9 | |
| Noah | 0 |
For this fictional policy, fewer than 5 hours earns no breaks, 5 to under 8 hours earns one, and 8 hours or more earns two. A zero-hour shift also earns zero breaks.
Put this formula in C2:
=IF(B2<5,0,IF(B2<8,1,2))
It returns 0 for Maya’s 3-hour shift. Filled down through C9, the results are 0, 0, 1, 1, 1, 2, 2, 0.
Close AND or OR before the next IF comma
This broken formula in C2:
=IF(AND(B2>=5,B2<8,1,IF(B2>=8,2,0)))
returns #N/A, with the message “Wrong number of arguments to IF. Expected between 2 and 3 arguments, but got 1 arguments.”
The intent was to test whether the shift lasted at least 5 hours but less than 8, then return one break. The closing parenthesis after B2<8 is missing, so the comma after B2<8 still belongs to AND. Sheets treats the entire AND expression as IF’s only argument:
IF(
AND(
condition 1,
condition 2,
1,
another IF
)
)
IF needs two or three arguments, not one. Close AND before you give IF its results:
=IF(AND(B2>=5,B2<8),1,IF(B2>=8,2,0))
That returns 0 in C2, 1 for Priya in C4, and 2 for Ethan in C7.
The only change is the parenthesis that moves the comma back into IF:
Wrong: AND(B2>=5,B2<8,1,
Right: AND(B2>=5,B2<8),1,
OR produces the same one-argument error:
=IF(OR(B2=5,B2=6,1,0))
Close OR first:
=IF(OR(B2=5,B2=6),1,0)
For Priya’s 5-hour shift in B4, this returns 1. For Lucas’s 6-hour shift in B5, it also returns 1. For Maya’s 3-hour shift in B2, it returns 0.
When the message says “got 1,” start with the first AND, OR, or other nested function, and find its intended closing parenthesis before you inspect the rest of the formula.
A nested IF that closes too early leaves a fourth argument
This formula looks almost right:
=IF(B2<5,0,IF(B2<8,1),2)
It returns #N/A, with the message “Wrong number of arguments to IF. Expected between 2 and 3 arguments, but got 4 arguments.”
The outer IF receives four arguments: B2<5, 0, the complete inner IF(B2<8,1), and 2. The inner IF is already finished because the closing parenthesis sits immediately after 1, so 2 has nowhere to go except onto the outer IF.
Move the parenthesis so 2 belongs to the inner IF:
=IF(B2<5,0,IF(B2<8,1,2))
This returns 0 for Maya, 1 for Priya, and 2 for Ethan. The endings are:
Wrong: IF(B2<8,1),2)
Right: IF(B2<8,1,2))
Counting every comma in the formula is not enough, because a nested IF has its own commas, and those commas are not arguments of the outer IF.
Use the “got N” count before you rewrite anything
| Error message | First place to inspect |
|---|---|
| Got 1 argument | An AND, OR, or nested function that wasn’t closed before the next IF argument |
| Got 4 arguments | A nested IF that closed too early, or an extra value on the outer IF |
| Got 5 or more arguments | Several conditions or results placed directly inside one IF |
For a long formula, start with the opening ( of an IF, then mark only the commas at that same parenthesis level.
IF does not take a list of condition-result pairs
This formula states the policy clearly, but it gives IF six arguments:
=IF(B2<5,0,B2<8,1,B2>=8,2)
The message is “Wrong number of arguments to IF. Expected between 2 and 3 arguments, but got 6 arguments.” IF only accepts IF(condition, value_if_true, value_if_false). The third argument is optional. Extra condition-and-result pairs are not.
The nested IF above is one fix. IFS is the other, because it is built to take those pairs:
=IFS(B2<5,0,B2<8,1,B2>=8,2)
In C2 this returns 0, in C4 it returns 1, and in C7 it returns 2.
IFS still needs at least one condition to be TRUE. This version:
=IFS(B2=5,1,B2=8,2)
returns #N/A for Maya’s 3 in B2, and the message is “No match.” Add a final TRUE condition when you want a default:
=IFS(B2=5,1,B2=8,2,TRUE,0)
That returns 0 for Maya, 1 for Priya, and 2 for Ethan. The final TRUE covers conditions that all evaluate to FALSE. It does not suppress errors produced while those conditions are evaluated. If you need to tell a missing match apart from another error, see IFERROR vs IFNA. For IFS results that calculate but look wrong, see IFS 函數傳回錯誤的值或 #N/A.
Two arguments are allowed; one is not
An IF with two arguments is valid. This formula:
=IF(B2>=8,2)
returns the Boolean FALSE in C2, where B2 is 3. In C7, where B7 is 8, it returns 2. That is not a wrong-number-of-arguments error. The omitted false result may still be the wrong fallback for a break count.
If zero breaks is the intended fallback, write it in:
=IF(B2>=8,2,0)
This returns 0 in C2 與 2 in C7.
By contrast, a single argument is not enough:
=IF(B2>=8)
That returns #N/A, with the same “got 1 arguments” message, because IF has a condition and nothing to return.
Empty hours and text hours still need a check
A formula can have the right number of arguments and still assign the wrong break count. With the working nested IF, a genuinely empty hours cell compares like zero and returns 0. That may be acceptable for a zero-hour shift, but it hides a missing timesheet entry.
To leave the break count blank until hours are entered:
=IF(B2="","",IF(B2<5,0,IF(B2<8,1,2)))
With Maya’s 3 in B2, it returns 0. If you clear B2, it returns an empty string, which displays as a blank cell. The same guard also catches a cell that looks blank but holds an empty string: ISBLANK is FALSE there, and without the guard the nested IF assigned two breaks, because an empty string is not less than 5 or 8. For the difference between a truly empty cell and "", see ISBLANK vs an Empty String.
Imported hours stored as text are a similar trap. =ISNUMBER(B2) returns TRUE for the numeric 3 in the sample table, and FALSE for the text string "3". That text value is not treated as the number 3 in the comparisons, so the unguarded nested IF assigned two breaks. To keep those values out of the calculation:
=IF(B2="","",IF(NOT(ISNUMBER(B2)),"Check hours",IF(B2<5,0,IF(B2<8,1,2))))
For the original numeric 3, this returns 0. For a blank cell, it displays nothing. For text such as "eight", or a text-stored "3", it returns Check hours. This checks whether the input is numeric; it does not validate that the hours are nonnegative or a plausible shift length.
Switch to IFS or a lookup table when the tiers multiply
I’d keep the nested IF for this three-tier break policy. It is short enough to read without repeatedly counting parentheses.
If the policy grows to five or six tiers, I’d switch to IFS:
=IFS(B2<5,0,B2<8,1,TRUE,2)
This returns 0 for Maya, 1 for Priya, and 2 for Ethan. The TRUE fallback means every numeric value that fails the first two tests receives two breaks, including values of 8 or more.
For a larger policy with thresholds that change often, a lookup table is easier to maintain. Put the headers in E1:F1 and these numeric thresholds in E2:F4:
| Minimum hours | Breaks |
|---|---|
| 0 | 0 |
| 5 | 1 |
| 8 | 2 |
Then use:
=VLOOKUP(B2,$E$2:$F$4,2,TRUE)
This returns 0 for Maya’s 3 hours, 1 for Priya’s 5 hours, and 2 for Ethan’s 8 hours. The first column must be sorted ascending for this approximate match. A negative value falls below the lowest threshold and returns #N/A, with the message “Did not find value ‘-1’ in VLOOKUP evaluation.” A text-stored "3" returns #N/A with “Did not find value ‘3’ in VLOOKUP evaluation.”
With a lookup table, changing a break threshold means editing a cell rather than rewriting a long formula.
The same message family on other functions, and semicolon locales
Don’t assume every argument-count error comes from a misplaced parenthesis in IF. Other functions have their own required argument counts, and sometimes the formula genuinely contains an unsupported extra parameter.
Regional separators matter when you copy a formula between spreadsheets. This comma version is the one the tests used:
=IF(B2<5,0,IF(B2<8,1,2))
Some locales use semicolons:
=IF(B2<5;0;IF(B2<8;1;2))
In a United States locale spreadsheet, entering the semicolon formula as user input stored it with commas and returned 0 for Maya’s 3-hour shift. A separator problem that Sheets cannot parse is a different error: the cell shows #ERROR!, and the note is a formula parse error. That is covered in the Google Sheets formula parse error guide.