IFS 返回错误值或 #N/A

72 分被判成 A、几乎每行都是 D、空白得 F,或出现 #N/A,原因并不相同。只在末尾加 TRUE 只能解决没有条件匹配的情况。在 2026 年 11 月 14 日的 Google Sheets 测试里,修好后的公式对样本返回 A、A、B、B、C、空白、D、F。

本文目录

快速解答

72 分被判成 A、几乎每行都是 D、空白得 F,或出现 #N/A,原因并不相同。只在末尾加 TRUE 只能解决没有条件匹配的情况。在 2026 年 11 月 14 日的 Google Sheets 测试里,修好后的公式对样本返回 A、A、B、B、C、空白、D、F。

=IFERROR(IF(B2="","",IFS(--B2>=90,"A",--B2>=80,"B",--B2>=70,"C",--B2>=60,"D",TRUE,"F")),"Check score")

检查要点

条件要从高到低写,否则 90 分会在 >=60 处停成 D。文本形式的 72 在 Sheets 里满足 >=90,甚至 >=1000 也为 TRUE,未转换的 IFS 得到 A;用 -- 或 VALUE 转换后得到 C。空白单元格的 B7<60 为 TRUE,--B7 为 0,未加判断的 IFS 得到 F。

边界与兼容性

截断值要用 >=。对正好 90 分用 > 会得到 B。测试里若出现 #DIV/0!,末尾的 TRUE 救不了,错误会传出去;用 IFERROR 和 ISERROR 处理后得到 Check score。超过四五档时,用升序阈值表做 XLOOKUP(匹配模式 -1)或 VLOOKUP(TRUE),本表得到与 IFS 相同的八个等级。Excel 未在本次复测。

完整英文示例、公式与作者备注

A score of 72 comes back as an A, almost every row is a D, a blank gets an F, or a few cells show #N/A. Those are different problems. Adding TRUE at the end only fixes the last one.

Type this into A1:B9. In B6, type a leading apostrophe before 72 ('72) so the cell displays 72 but is stored as text, the way a score often arrives from a CSV or a web form. Leave B7 empty.

StudentScore
Maya Chen94
Luis Garcia90
Nia Patel87
Omar Hassan80
Priya Shah72
Remy Brooks
Sofia Kim60
Theo Martin59

The bands are A for 90 or above, B for 80–89, C for 70–79, D for 60–69, and F below 60. A missing score should stay ungraded.

In C2, fill down to C9:

=IFERROR(IF(B2="","",IFS(--B2>=90,"A",--B2>=80,"B",--B2>=70,"C",--B2>=60,"D",TRUE,"F")),"Check score")

C2:C9 returns A, A, B, B, C, blank, D, F. The -- turns numeric text into a number, the IF leaves an empty score blank, the tests run from high to low, TRUE,"F" catches anything below 60, and IFERROR shows “Check score” when the input can’t be converted. I ran these checks in Google Sheets on 14 November 2026.

No condition matches, so IFS returns #N/A

Theo’s 59 in B9 matches none of these four tests, so this formula returns #N/A:

=IFS(B9>=90,"A",B9>=80,"B",B9>=70,"C",B9>=60,"D")

Add a final pair. =IFS(B9>=90,"A",B9>=80,"B",B9>=70,"C",B9>=60,"D",TRUE,"F") returns F. Wrapping the same four-test formula in IFNA also returns F. I’d use the TRUE pair: it states the default. IFNA will also replace an #N/A that came from inside a more complicated test; when to mask an error is in IFERROR vs IFNA.

Tests that start too low turn a 90 into a D

IFS stops at the first TRUE. =IFS(B3>=60,"D",B3>=70,"C",B3>=80,"B",B3>=90,"A",TRUE,"F") returns D for Luis’s 90, because B3>=60 is already TRUE. Every numeric score of 60 or more would get D with that order.

For >= bands, put the highest cutoff first: =IFS(B3>=90,"A",B3>=80,"B",B3>=70,"C",B3>=60,"D",TRUE,"F") returns A. If you write the tests as “below 60, below 70,” the order goes the other way, lowest first. Nested IF follows the same first-true-wins rule.

Imported 72 gets an A because it’s text

This is the one I’d look at first when hand-typed scores grade correctly and imported ones jump to the top band.

Priya’s B6 displays 72 but is text: =ISNUMBER(B6) returns FALSE. This formula returns A, not C:

=IFS(B6>=90,"A",B6>=80,"B",B6>=70,"C",B6>=60,"D",TRUE,"F")

In Google Sheets, =B6>=90 and even =B6>=1000 both returned TRUE. The comparison is not numeric. A text value ranks above a number, so the first test succeeds and IFS never looks at the later bands. I did not re-run those comparisons in Excel for this page.

Convert the score inside the tests. =IFS(--B6>=90,"A",--B6>=80,"B",--B6>=70,"C",--B6>=60,"D",TRUE,"F") returns C, and VALUE(B6) does the same. If B6 held a word such as absent, both conversions return #VALUE!; the opening formula’s IFERROR then shows “Check score”.

For a one-off import, I’d convert the column to real numbers rather than wrap every formula; converting numbers stored as text covers that. For a feed you re-import, keep the conversion in the formula.

Blank cells grade as F because they compare like zero

=B7<60 returns TRUE on the empty cell, and --B7 returns 0. An unguarded =IFS(B7>=90,"A",B7>=80,"B",B7>=70,"C",B7>=60,"D",TRUE,"F") therefore returns F: none of the positive cutoffs match, and the fallback treats the blank like a low score.

If a missing score should stay ungraded, test for it first. =IF(B7="","",IFS(B7>=90,"A",B7>=80,"B",B7>=70,"C",B7>=60,"D",TRUE,"F")) returns a blank. That also treats a formula that returns "" as missing; distinguishing that from a truly empty cell is in ISBLANK vs empty cells. A real score of 0 should still be F.

An exact 90 becomes B when the cutoff is >

=IFS(B3>90,"A",B3>80,"B",B3>70,"C",B3>60,"D",TRUE,"F") returns B for Luis’s 90, because B3>90 is FALSE and B3>80 is TRUE. If 90 belongs in the A band, use >=90. The same >= formula returns B for Omar’s exact 80 and D for Sofia’s exact 60.

TRUE does not catch an error inside a test

A final TRUE pair covers tests that come back FALSE. It does not catch a test that returns an error.

I put =1/0 in B11, which displays #DIV/0!. =IFS(B11>=90,"A",TRUE,"Not A") returns #DIV/0!, not “Not A”. Handle the failure in the test:

=IFS(IFERROR(B11>=90,FALSE),"A",ISERROR(B11),"Check score",TRUE,"Not A")

That returns “Check score” while B11 is an error, and “Not A” for Theo’s 59.

Use a threshold table once you have more than a few bands

IFS is fine for five grades. Once the list grows, I’d keep the cutoffs in a table. Enter this in E1:F6, with E2:E6 in ascending order:

Minimum scoreGrade
0F
60D
70C
80B
90A

In C2, fill down:

=IF(B2="","",XLOOKUP(--B2,$E$2:$E$6,$F$2:$F$6,"No tier",-1))

It returns the same A, A, B, B, C, blank, D, F. The -1 match mode takes an exact match or the next smaller threshold, so 87 becomes B. A score below 0 returns “No tier”.

XLOOKUP is in Microsoft 365, Excel 2021 and later, and Google Sheets, not in Excel 2019. There, =IF(B2="","",VLOOKUP(--B2,$E$2:$F$6,2,TRUE)) returned the same grades on this sample. The first column has to stay sorted ascending. If the B minimum moves from 80 to 82, you edit E5 instead of hunting through formulas. More on the lookup functions is in XLOOKUP vs INDEX MATCH vs VLOOKUP.

IFS itself is in Excel 2019, Excel 2021, Microsoft 365, and Google Sheets. On older Excel, a nested IF with the same --, blank check, and high-to-low order produced the same eight grades:

=IF(B2="","",IFERROR(IF(--B2>=90,"A",IF(--B2>=80,"B",IF(--B2>=70,"C",IF(--B2>=60,"D","F")))),"Check score"))
Oscar

专注电子表格公式与排错;具体测试环境和待验证事项见各篇文章。

Google Sheets, 14 November 2026, tab ifs-wrong-result. Main IFS and nested IF in C2:C9 and D2:D9 returned A, A, B, B, C, blank, D, F. IFS without a default on 59 returned #N/A; TRUE,"F" and IFNA both returned F. Low-to-high order on 90 returned D; high-to-low returned A. Text-stored 72: ISNUMBER FALSE, ISTEXT TRUE, LEN 2, B6>=90 and B6>=1000 TRUE, unconverted IFS A, VALUE and -- both C. Blank B7: ISBLANK TRUE, B7<60 TRUE, --B7 0, unguarded IFS F, IF guard blank. Strict > on 90 returned B; >= on 80 returned B and on 60 returned D. =1/0 in a test with TRUE fallback returned #DIV/0!; IFERROR/ISERROR wrapper returned Check score, and Not A on 59. VALUE("absent") #VALUE!, main IFERROR formula Check score. XLOOKUP match mode -1 and VLOOKUP TRUE on E2:F6 returned the same eight grades; XLOOKUP of -1 returned No tier. Excel was not re-run.

本主题下一篇:表格错误与动态数组 修复 IMPORTRANGE 的 #REF! “You Need to Connect These Sheets”错误