Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

XL.ConditionalFormating.AddRule

Adds a conditional formatting rule that highlights cells whose values correspond to the specified criteria.

Component Version macOS Windows Linux Server iOS SDK
XL 14.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "XL.ConditionalFormating.AddRule"; bookRef; ConditionalFormattingRef; FormatType; ConditionalFormatRef { ; Value; stopIfTrue } )   More

Parameters

Parameter Description Example Flags
bookRef The reference to the workbook. Please use XL.LoadBook to load a file. $ref
ConditionalFormattingRef The reference number for the conditional formatting. $ConditionalFormatting
FormatType The conditional format rule type, see the list of types below. 0
ConditionalFormatRef The reference number for the conditional format.
The conditional format used for highlighting cells, use the XL.Book.AddConditionalFormat for adding conditional formats.
$ConditionalFormat
Value Specifies the criteria for the conditional formatting rule.
Default is false.
Optional
stopIfTrue if true, no rules with lower priority may be applied over this rule, when this rule is true.
Default is false.
false Optional

Result

Returns OK or error.

Description

Adds a conditional formatting rule that highlights cells whose values correspond to the specified criteria.
Available format types:

NameValueDescription
CFORMAT_BEGINWITH0highlights cells that begin with the given text
CFORMAT_CONTAINSBLANKS1highlights cells that are completely blank
CFORMAT_CONTAINSERRORS2highlights cells with formula errors
CFORMAT_CONTAINSTEXT3highlights cells containing given text
CFORMAT_DUPLICATEVALUES4highlights duplicated values
CFORMAT_ENDSWITH5highlights cells ending with given text
CFORMAT_EXPRESSION6highlights cells when the formula result is true
CFORMAT_NOTCONTAINSBLANKS7highlights cells that are not blank
CFORMAT_NOTCONTAINSERRORS8highlights cells without formula errors
CFORMAT_NOTCONTAINSTEXT9highlights cells that do not contain given text
CFORMAT_UNIQUEVALUES10highlights unique values in the range

Examples

Highlighting cells that begin With the given text:

# add conditional format
Set Variable [ $cFormat ; Value: MBS("XL.Book.AddConditionalFormat"; $book) ]
#
# set font to be folder
Set Variable [ $font ; Value: MBS("XL.ConditionalFormat.Font"; $book; $cFormat) ]
Set Variable [ $r ; Value: MBS("XL.Font.SetBold"; $book; $font; 1) ]
#
Set Variable [ $CF ; Value: MBS("XL.Sheet.AddConditionalFormatting"; $book; $sheet) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormating.AddRange"; $book; $CF; 2; 10; 1; 1) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormating.AddRule"; $book; $CF; 0 /* BeginWith */; $cFormat; "a") ]

Highlighting alternating rows:

# add conditional format
Set Variable [ $cFormat ; Value: MBS("XL.Book.AddConditionalFormat"; $book) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormat.SetFillPattern"; $book; $cFormat; 1 /* solid */) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormat.SetPatternBackgroundColor"; $book; $cFormat; MBS("XL.Color.Pack"; $book; 240; 240; 240)) ]
#
Set Variable [ $CF ; Value: MBS("XL.Sheet.AddConditionalFormatting"; $book; $sheet) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormating.AddRange"; $book; $CF; 4; 20; 1; 10) ]
Set Variable [ $r ; Value: MBS("XL.ConditionalFormating.AddRule"; $book; $CF; 6 /* Expression */; $cFormat; "=MOD(ROW(),2)=0") ]

See also

Example Databases

Blog Entries

Created 30th March 2024, last changed 31st March 2024


XL.ConditionalFormating.AddRange - XL.ConditionalFormating.AddTimePeriodRule