Google Sheets Conditional Formatting: Invalid Formula

Fix the Invalid formula error in Google Sheets conditional formatting. Use INDIRECT for other sheets, and check curly quotes and locale separators.

本文目录

Your custom formula works in a Google Sheets cell, but Custom formula is rejects it as invalid. Or the rule saves, and none of the cells change color.

A stock table you can rebuild

Create a sheet named Orders and enter this table in A1:D8.

SKURegionQtyReorder level
KB-101East620300
MS-204West180200
HD-310East450250
CB-115North780400
MN-220East540300
AD-108West90150
USB-305South500200

On a second sheet named Settings, enter 500 in A1.

If the formula points at another sheet, start there. This comparison is valid in an ordinary cell on Orders and is rejected as a conditional formatting rule:

=$C2>=Settings!$A$1

Use INDIRECT instead:

=$C2>=INDIRECT("Settings!A1")

Select Orders!A2:D8, open Format > Conditional formatting, choose “Custom formula is”, and enter the INDIRECT formula. The rule highlights rows 2, 5, 6, and 8: KB-101, CB-115, MN-220, and USB-305. Changing Settings!A1 from 500 to 600 leaves only rows 2 and 5 highlighted.

The same comparison with a direct Settings!$A$1 reference returns those same TRUE and FALSE values when you enter it in column E and fill it down. It is rejected when you try to use it as the custom formula for the rule.

Google Sheets with E2 selected, showing =$C2>=Settings!$A$1 in the formula bar. Column E returns TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, and the INDIRECT custom-formula rule on A2:D8 highlights rows 2, 5, 6 and 8: KB-101, CB-115, MN-220 and USB-305.
Screenshot: Google Sheets, Nov 2026

When the other sheet name has a space

Create a third sheet named Stock List and enter these SKUs in A1:A6.

SKU
KB-101
HD-310
MN-220
USB-305
SP-410

This COUNTIF is also valid in an ordinary cell and is rejected as a custom formatting formula, because of the direct reference to Stock List:

=COUNTIF('Stock List'!A2:A,$A2)>0

Use this version instead, applied to A2:D8:

=COUNTIF(INDIRECT("'Stock List'!A2:A"),$A2)>0

It highlights rows 2, 4, 6, and 8, the four orders whose SKUs appear on Stock List. COUNTIF returns 1 for KB-101 and 0 for MS-204; the >0 turns those counts into TRUE and FALSE. A duplicate SKU on the list would still satisfy >0.

The address passed to INDIRECT uses two kinds of quotation marks: double quotes around the whole address, and single quotes around the sheet name because that name contains a space.

A blank order SKU does not get picked up by this formula. In this test, COUNTIF of a genuine blank cell against Stock List!A2:A returned 0, so >0 was already FALSE. That is not the same as COUNTIF(range,""), which did count the empty cells in the same open-ended column (994 of them). The blank lookup value did not match those empties.

INDIRECT does not walk down the sheet

These two expressions both return 500 on every row of the sample:

=INDIRECT("Settings!A1")
=INDIRECT("Settings!$A$1")

The dollar signs inside the quoted address do not matter. The address is text, so Google Sheets does not advance it to A2, A3, or A4 as the rule moves down the applied range. The COUNTIF example avoids that problem by keeping the lookup range fixed and letting $A2, the SKU being checked, change for each row. For a row-by-row comparison against another sheet, I would bring the values onto this sheet with a helper column instead of building a changing address inside INDIRECT.

Named ranges are not a shortcut in the rule itself

A named range such as Threshold, pointing at Settings!A1, works in an ordinary cell:

=$C2>=Threshold

That formula returns the same seven TRUE and FALSE values as the INDIRECT comparison. As a custom formatting formula it is rejected, and so is a named range that points at a cell on the same sheet. What did work in the rule is wrapping the name in INDIRECT:

=$C2>=INDIRECT("Threshold")

Applied to A2:D8, it highlights rows 2, 5, 6, and 8. I would still rather use a helper column when several rules depend on another sheet, for the rename problem at the end of this article.

Curly quotation marks

If you have already switched to INDIRECT and the custom formula is still rejected, look at the quotation marks. This version uses curly quotes and is not valid spreadsheet syntax:

=$C2>=INDIRECT(“Settings!A1”)

In an ordinary cell it returns #ERROR!, with the message “Formula parse error.” As a custom formatting formula it is rejected. Type straight double quotes from the keyboard:

=$C2>=INDIRECT("Settings!A1")

That formula returns TRUE for row 2 and, applied to A2:D8, highlights rows 2, 5, 6, and 8. Curly quotes often arrive when you paste a formula from a word processor, a messaging app, or a formatted web page. If the sheet name has spaces, check the single quotes around that name as well.

Missing equals, quoted formulas, and non-Boolean results

A custom formula needs a leading = and a condition that evaluates to TRUE or FALSE. These two entries are rejected as custom formulas:

$C2>=$D2
"=$C2>=$D2"

Enter the comparison directly:

=$C2>=$D2

Applied to A2:D8, that rule highlights rows 2, 4, 5, 6, and 8, the orders whose quantities meet or exceed their own reorder levels.

A related mistake is a calculation with no comparison:

=$C2-$D2

In this sample the differences are 320, -20, 200, 380, 240, -60, and 300. The custom formula is accepted, and it highlights every one of those seven rows, because a nonzero number is treated as a match. A negative result such as -20 is highlighted just as a positive 320 is. In a separate type check, 0, FALSE, the text hello, an empty string, and a blank cell were not highlighted.

If the aim is to flag orders below their reorder level, write the comparison:

=$C2-$D2<0

That returns TRUE only for MS-204 and AD-108, and highlights rows 3 and 7.

Google Sheets with E3 selected, showing =$C3-$D3<0 in the formula bar and TRUE in E3. The custom-formula rule =$C2-$D2<0 on A2:D8 highlights rows 3 and 7, MS-204 and AD-108, whose quantities are below their reorder levels.
Screenshot: Google Sheets, Nov 2026

Commas and semicolons follow the spreadsheet locale

A formula copied from another spreadsheet may use semicolons between function arguments instead of commas. For highlighting East-region orders with a quantity of at least 500, these two are the same condition:

=AND($B2="East",$C2>=500)
=AND($B2="East";$C2>=500)

With the separator the spreadsheet expects, the rule highlights rows 2 and 6, KB-101 and MN-220.

The locale belongs to the spreadsheet, under File > Settings, not just to your Google account or browser language. In a US-locale file, the semicolon formula was accepted both in a cell and as a custom formatting rule, then stored with commas, and it highlighted those two rows. In a German-locale file the direction is not symmetric: the comma formula returned #ERROR!, “Formula parse error,” in a cell and was rejected as a custom formula, while the semicolon formula was stored with semicolons, returned TRUE on rows 2 and 6, and highlighted those rows.

If the same formula also fails in an ordinary cell, see Formula parse error in Google Sheets for other syntax problems, including curly quotes and Excel syntax.

Formulas pasted from Excel

A custom formula pasted from Excel may include a structured table reference or a function prefix that Google Sheets does not evaluate the same way. With no table named Table1 in the file, these two returned #ERROR!, “Formula parse error,” in ordinary cells and were rejected as custom formulas:

=Table1[Qty]>=500
=[@Qty]>=500

I did not test those references against a real Google Sheets table. For this Orders sample, use ordinary cell references:

=$C2>=500

Applied to A2:D8, that highlights rows 2, 5, 6, and 8.

A formula with an Excel-only prefix can fail in a different way. =_xlfn.XLOOKUP(1,A1,A1) returned #NAME? in a cell, with the message “Unknown function: ‘_xlfn.XLOOKUP’.” As a custom formatting rule the same kind of formula was accepted, but it highlighted no cells. A rule that saves is not proof that it is highlighting the rows you expect.

Wrong rows, drifting columns, and text quantities

Once the formula is accepted, the usual problem is the relationship between the formula and the applied range, or the type of the values being compared.

Starting one row too high

If “Apply to range” is A2:D8, write the formula for row 2, not row 1. This formula is valid, but it is aimed one row too high:

=$C1>=500

Row 3, MS-204, is evaluated against C2, which contains 620, so that row is highlighted even though its own quantity is 180. Row 2 is evaluated against C1, the header Qty. In this test "Qty">=500 returned TRUE, so row 2 was highlighted as well. Rows 6 and 7 were also highlighted, because they picked up 780 and 540 from the rows above them. The intended formula is:

=$C2>=500

Column references that drift

When you want the whole row highlighted, this formula is missing the dollar sign before C:

=C2>=500

The column moves as the rule is evaluated across A2:D8. In row 2, A2 is tested against C2 (620), which meets the condition, but B2 is tested against D2 (300), which does not. Only column A of rows 2, 5, 6, and 8 is highlighted. Lock the column and leave the row relative:

=$C2>=500

Every cell in row 2 then uses the quantity in C2, so the whole row highlights. For more on anchoring a rule to the first cell of the applied range, see Conditional formatting formula not working 与 Conditional formatting based on another cell.

Quantities stored as text

Imported quantities sometimes look like numbers but are stored as text. To reproduce this, type a leading apostrophe before the 180 in C3. The cell still displays 180.

=ISNUMBER(C3)

That returns FALSE. The same check on the numeric 620 in C2 returns TRUE. Google Sheets does not compare that text 180 as the number 180: =$C3>=500 returns TRUE, and a =$C2>=500 rule applied to A2:D8 highlights MS-204 along with the four genuine matches. After C3 is converted back to the number 180, the comparison returns FALSE and the highlight on that row disappears.

If you only want genuine numeric quantities, add an ISNUMBER check:

=AND(ISNUMBER($C2),$C2>=500)

Applied to A2:D8 while C3 still held text 180, this highlighted rows 2, 5, 6, and 8 and skipped the text quantity. The guard does not convert text into numbers. Fix the imported values if those quantities should take part in the comparison.

Helper columns survive a renamed sheet

For a single threshold on another sheet, INDIRECT is a reasonable fix. On a shared spreadsheet with several cross-sheet rules, I would rather use a visible helper column.

In E2, enter the direct comparison and fill it down through E8:

=$C2>=Settings!$A$1

Direct cross-sheet references are allowed here, because these are ordinary worksheet formulas. With the original sample and a threshold of 500, E2:E8 contains TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, and TRUE. Then apply this custom formula to A2:D8:

=$E2=TRUE

It highlights rows 2, 5, 6, and 8, and you can see why each row was included without opening the rule editor.

INDIRECT has a maintenance cost that the helper column does not. If someone renames Settings to Rules, Google Sheets does not update the address stored inside "Settings!A1". After that rename, the ordinary formula =$C2>=Settings!$A$1 became =$C2>=Rules!$A$1 and still returned the original Booleans. =INDIRECT("Settings!A1") still contained the old sheet name and returned #REF!, with the message “Function INDIRECT parameter 1 value is ‘Settings!A1’. It is not a valid cell/range reference.” The custom formula that used that INDIRECT expression stayed saved and highlighted no cells.

A named range still resolved after the rename, and =INDIRECT("Threshold") kept highlighting rows 2, 5, 6, and 8. The helper column of direct references also kept working, because those references were updated with the tab name.

If you are already troubleshooting a rule, put its condition into an unused cell on the first row of the applied range and fill it down. A formula that returns the right Booleans in ordinary cells, but is rejected as a custom formula, is hitting a restriction in the rule. A formula that returns the wrong values in those cells needs its logic or references corrected before formatting enters the picture.

Oscar

写 Excel 与 Google Sheets 的公式和排错。

Google Sheets, 25 November 2026, two new private unshared spreadsheets (locale en_US, 1000-row grid; a second new file set to de_DE only). Formulas were entered as user input through the Sheets API. Conditional formatting rules were added as CUSTOM_FORMULA through the same API; a rejected rule returned HTTP 400, invalid custom formula. Highlights were read from effectiveFormat.backgroundColor. Error text was read from the Sheets API error message. The editor UI was not opened. On the Orders sample (A2:D8) with Settings!A1 equal to 500, =$C2>=Settings!$A$1, =$C2>=INDIRECT("Settings!A1"), =$C2>=INDIRECT("Settings!$A$1"), and =$C2>=Threshold each returned TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE in ordinary cells. The direct Settings reference was rejected as a custom formatting formula. The INDIRECT("Settings!A1") rule highlighted rows 2, 5, 6, and 8. Changing Settings!A1 to 600 left only rows 2 and 5 highlighted. INDIRECT("Settings!A1") and INDIRECT("Settings!$A$1") both returned 500 on every row. COUNTIF of Stock List!A2:A, and the same range through INDIRECT, returned TRUE on rows 2, 4, 6, and 8; the INDIRECT form highlighted those four rows, and the direct cross-sheet COUNTIF was rejected as a custom formula. COUNTIF of a genuine blank criterion against A2:A20 returned 0, while COUNTIF(A2:A20,"") and COUNTBLANK(A2:A20) were both 14, and COUNTIF(A2:A,"") was 994. Bare named ranges Threshold (Settings!A1) and LocalThreshold (same-sheet Z1) were rejected as custom formulas. =$C2>=INDIRECT("Threshold") was accepted and highlighted rows 2, 5, 6, and 8. Curly quotes in INDIRECT(“Settings!A1”) returned #ERROR!, "Formula parse error." in a cell and were rejected as a custom formula. A formula missing the leading equals sign, and a fully quoted "=$C2>=$D2", were rejected as custom formulas. =$C2>=$D2 highlighted rows 2, 4, 5, 6, and 8. =$C2-$D2 was accepted and highlighted all seven data rows (differences 320, -20, 200, 380, 240, -60, 300). On a type sample, a custom formula equal to the cell itself highlighted 320, -20, and TRUE, and did not highlight 0, the text hello, an empty string, FALSE, or a blank cell. =$C2-$D2<0 highlighted rows 3 and 7. In the en_US file, =AND($B2="East";$C2>=500) was accepted in a cell and as a custom formula, stored with commas, and highlighted rows 2 and 6. In the de_DE file, the comma form returned #ERROR!, "Formula parse error." in a cell and was rejected as a custom formula; the semicolon form was stored with semicolons, returned TRUE on rows 2 and 6, and highlighted those rows. =$C2>=500 highlighted rows 2, 5, 6, and 8. =$C1>=500 applied to A2:D8 highlighted rows 2, 3, 6, and 7; "Qty">=500 and C1>=500 were TRUE because C1 is text. =C2>=500 applied to A2:D8 highlighted A2, A5, A6, and A8 only; B2 (evaluated against D2=300) was not highlighted. A leading-apostrophe 180 in C3 had stringValue "180", ISNUMBER FALSE, ISTEXT TRUE, and $C3>=500 TRUE, and the >=500 rule highlighted that row; after converting C3 to the number 180 the comparison was FALSE and the highlight was gone. =AND(ISNUMBER($C2),$C2>=500) highlighted rows 2, 5, 6, and 8 while C3 was text. Table1[Qty]>=500 and [@Qty]>=500, with no table present, returned #ERROR!, "Formula parse error." in cells and were rejected as custom formulas. =_xlfn.XLOOKUP(1,A1,A1) returned #NAME?, "Unknown function: '_xlfn.XLOOKUP'." in a cell; as a custom formula the rule was accepted and highlighted no cells. After renaming Settings to Rules, =$C2>=Settings!$A$1 became =$C2>=Rules!$A$1 and still returned the original Booleans; INDIRECT("Settings!A1") returned #REF!, "Function INDIRECT parameter 1 value is 'Settings!A1'. It is not a valid cell/range reference."; that custom formula remained saved and highlighted nothing; INDIRECT("Threshold") and =$C2>=Threshold still worked, and the INDIRECT("Threshold") rule still highlighted rows 2, 5, 6, and 8. The tab was renamed back to Settings after the check. =$E2=TRUE, with column E holding the direct Settings comparison, highlighted rows 2, 5, 6, and 8. Excel was not run.

本主题下一篇:数据清理与录入 Google Sheets 中如何使用条件格式突出显示两列中的重复值