Conditional Cell Formatting

1. Function Overview

setFormatIf(reference, action, if_condition, format_true, format_false)

This function formats a cell or range of cells. The numeric action parameter specifies which formatting attributes to set or clear (restore defaults).

It is often convenient to keep formatting formulas in a separate worksheet so a single control cell can affect formatting across multiple sheets.

The function works on both existing cells and empty regions. There are no limits on the number or complexity of conditional formatting operations — millions of cells may be formatted using nested IFs or other formulas.

2. Formatting Layers

If reference specifies entire columns or rows, formatting applies to column or row styles. Formatting precedence:

table style < column styles < row styles < cell styles

Cell styles override all other styles.

3. format_true / format_false Values

Values may be -1 (restore default) or one of the following:

4. Custom Cell Styles

action = 32 applies all formatting attributes using a named custom style. Custom styles are created in Format > Custom Cell Styles and saved in the workbook.

They may also be saved to or loaded from the global GS-Calc cache using:

5. Border Formatting (action = 20)

position may include:

width may be:

style may be:

color may be an RGB value, “#RRGGBB”, or one of:

6. Return Value

The function returns the evaluated value of if_condition.

7. Custom Cell Styles Dialog

*
*

8. Examples

setFormatIf(c120, 11, c120 > 0, "green", "red")

setFormatIf(c:e, 11, c120 > 0, "green", "red")

setFormatIf(10:20, 11, c120 > 0, "green", "red")

setFormatIf(c120, 20, c120 > 0, "all 2px solid green", "diag-left diag-right red")

setFormatIf(d100:d999, 1, c1="use format", "currency", 0)

setFormatIf(d99, 20, a1, "bottom 2px dotted green", -1)

setFormatIf(d99, 32, a10 > 10, "my-style-1", "my-style-2")