XL.Sheet.AddConditionalFormatting
---------------------------------

Adds a conditional formatting rules to the sheet.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [XL](component_XL.md) | [14.2](newinversion142.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "XL.Sheet.AddConditionalFormatting"; BookRef; SheetIndex; rowFirst; rowLast; ColFirst; ColLast ) 

**MBS**( **"XL.Sheet.AddConditionalFormatting";** /\* Adds a conditional formatting rules to the sheet. \*/  
**$BookRef**; /\* The reference number for the workbook.e.g. $ref \*/   
**$SheetIndex**; /\* The index of the sheet. This number ranges from 0 to [XL.Book.SheetCount](XLBookSheetCount.md)-1.e.g. 0 \*/   
**$rowFirst**; /\* The first row for the area. First row has index 0.e.g. $row \*/   
**$rowLast**; /\* The last row for the area. First row has index 0.e.g. $row \*/   
**$ColFirst**; /\* The first column for the area. First column has index 0.e.g. $column \*/   
**$ColLast**) /\* The last column for the area. First column has index 0.e.g. $column+1 \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| BookRef | The reference number for the workbook. | $ref |
| SheetIndex | The index of the sheet. This number ranges from 0 to [XL.Book.SheetCount](XLBookSheetCount.md)-1. | 0 |
| rowFirst | The first row for the area. First row has index 0. | $row |
| rowLast | The last row for the area. First row has index 0. | $row |
| ColFirst | The first column for the area. First column has index 0. | $column |
| ColLast | The last column for the area. First column has index 0. | $column+1 |

### Result

Returns conditional formatting index number or error.

### Description

Adds a conditional formatting rules to the sheet.  
Requires LibXL 4.1 and only for xlsx files.  
  
With version 5.1 you need to pass a rectangle here for the first range.  
### Examples

Highlighting alternating rows:

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

- [XL.ConditionalFormat.SetBorder](XLConditionalFormatSetBorder.md)
- [XL.ConditionalFormat.SetBorderBottom](XLConditionalFormatSetBorderBottom.md)
- [XL.ConditionalFormat.SetBorderRight](XLConditionalFormatSetBorderRight.md)
- [XL.ConditionalFormating.Add2ColorScaleRule](XLConditionalFormatingAdd2ColorScaleRule.md)
- [XL.ConditionalFormating.AddOpNumRule](XLConditionalFormatingAddOpNumRule.md)
- [XL.ConditionalFormating.AddRange](XLConditionalFormatingAddRange.md)
- [XL.ConditionalFormating.AddRule](XLConditionalFormatingAddRule.md)
- [XL.Sheet.ConditionalFormatSize](XLSheetConditionalFormatSize.md)
- [XL.Sheet.ConditionalFormatting](XLSheetConditionalFormatting.md)
- [XL.Sheet.RemoveConditionalFormatting](XLSheetRemoveConditionalFormatting.md)

### Release notes

- **Version 16.1**
    - Changed [XL.Sheet.AddConditionalFormatting](https://www.mbsplugins.eu/XLSheetAddConditionalFormatting.shtml) so you pass the first range with the function call.
- **Version 14.2**
    - Added new [XL](https://www.mbsplugins.eu/component_XL.shtml) functions to create conditional formatting including [XL.Book.AddConditionalFormat](https://www.mbsplugins.eu/XLBookAddConditionalFormat.shtml) and [XL.Sheet.AddConditionalFormatting](https://www.mbsplugins.eu/XLSheetAddConditionalFormatting.shtml).

### Blog Entries

- [MBS FileMaker Plugin, version 16.1pr1](https://www.mbsplugins.de/archive/2026-02-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Neues MBS Plugin 14.2 für Claris FileMaker](https://www.mbsplugins.de/archive/2024-05-14/Neues_MBS_Plugin_142_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 14.2 for Claris FileMaker](https://www.mbsplugins.de/archive/2024-05-14/MBS_Plugin_142_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [Conditional Formatting in Excel exports from FileMaker](https://www.mbsplugins.de/archive/2024-04-08/Conditional_Formatting_in_Exce/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.2pr1](https://www.mbsplugins.de/archive/2024-04-02/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

Created 30th March 2024 , last changed 30th January 2026

  
[XL.NewBook](XLNewBook.md) - [XL.Sheet.AddDataValidation](XLSheetAddDataValidation.md)

[HTML Version](XLSheetAddConditionalFormatting.shtml)