XL.ConditionalFormating.AddTopRule
----------------------------------

Adds a conditional formatting rule that highlights cells whose values fall in the \[top N\] or \[bottom N\] bracket.

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

MBS( "XL.ConditionalFormating.AddTopRule"; BookRef; ConditionalFormattingRef; ConditionalFormatRef { ; Value; Bottom; Percent; StopIfTrue } ) 

**MBS**( **"XL.ConditionalFormating.AddTopRule";** /\* Adds a conditional formatting rule that highlights cells whose values fall in the \[top N\] or \[bottom N\] bracket. \*/  
**$BookRef**; /\* The reference number for the workbook.e.g. $ref \*/   
**$ConditionalFormattingRef**; /\* The reference number for the conditional formatting.e.g. $ConditionalFormatting \*/   
**$ConditionalFormatRef**; /\* The reference number for the conditional format.  
The conditional format used for highlighting cells, use the [XL.Book.AddConditionalFormat](XLBookAddConditionalFormat.md) for adding conditional formats.e.g. $ConditionalFormat \*/   
**$Value**; /\* Optional; Specifies the \[top N\] or \[bottom N\] bracket.  
Default is 0.e.g. 0 \*/   
**$Bottom**; /\* Optional; True for a \[bottom N\] rule, false for a \[top N\] rule.  
Default is false. \*/   
**$Percent**; /\* Optional; True for a percent top/bottom rule.  
Default is false. \*/   
**$StopIfTrue**) /\* Optional; If true, no rules with lower priority may be applied over this rule, when this rule is true.  
Default is false. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| BookRef | The reference number for the workbook. | $ref |  |
| ConditionalFormattingRef | The reference number for the conditional formatting. | $ConditionalFormatting |  |
| ConditionalFormatRef | The reference number for the conditional format.   The conditional format used for highlighting cells, use the [XL.Book.AddConditionalFormat](XLBookAddConditionalFormat.md) for adding conditional formats. | $ConditionalFormat |  |
| Value | Specifies the \[top N\] or \[bottom N\] bracket.   Default is 0. | 0 | Optional |
| Bottom | True for a \[bottom N\] rule, false for a \[top N\] rule.   Default is false. |  | Optional |
| Percent | True for a percent top/bottom 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. |  | Optional |

### Result

Returns OK or error.

### Description

Adds a conditional formatting rule that highlights cells whose values fall in the \[top N\] or \[bottom N\] bracket.  
### See also

- [XL.Book.AddConditionalFormat](XLBookAddConditionalFormat.md)
- [XL.ConditionalFormating.Add2ColorScaleRule](XLConditionalFormatingAdd2ColorScaleRule.md)
- [XL.ConditionalFormating.Add3ColorScaleRule](XLConditionalFormatingAdd3ColorScaleRule.md)
- [XL.ConditionalFormating.AddOpNumRule](XLConditionalFormatingAddOpNumRule.md)
- [XL.ConditionalFormating.AddOpStrRule](XLConditionalFormatingAddOpStrRule.md)
- [XL.ConditionalFormating.AddRange](XLConditionalFormatingAddRange.md)
- [XL.ConditionalFormating.AddRule](XLConditionalFormatingAddRule.md)
- [XL.ConditionalFormating.AddTimePeriodRule](XLConditionalFormatingAddTimePeriodRule.md)

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

  
[XL.ConditionalFormating.AddTimePeriodRule](XLConditionalFormatingAddTimePeriodRule.md) - [XL.CopyCellValue](XLCopyCellValue.md)

[HTML Version](XLConditionalFormatingAddTopRule.shtml)