XL.ConditionalFormating.Add2ColorScaleRule
------------------------------------------

Adds a conditional formatting rule that creates a gradated 2-color scale on the cells.

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

MBS( "XL.ConditionalFormating.Add2ColorScaleRule"; BookRef; ConditionalFormattingRef; minColor; maxColor { ; minType; minValue; maxType; maxValue; StopIfTrue } ) 

**MBS**( **"XL.ConditionalFormating.Add2ColorScaleRule";** /\* Adds a conditional formatting rule that creates a gradated 2-color scale on the cells. \*/  
**$BookRef**; /\* The reference number for the workbook.e.g. $ref \*/   
**$ConditionalFormattingRef**; /\* The reference number for the conditional formatting.e.g. $ConditionalFormatting \*/   
**$minColor**; /\* the color for minimum \*/   
**$maxColor**; /\* the color for maximum \*/   
**$minType**; /\* Optional; the type of minValue, see values below.  
Defaults to 0 for CFVO\_MIN.e.g. 0 \*/   
**$minValue**; /\* Optional; The numeric value for minimum.  
Default is 0.e.g. 0 \*/   
**$maxType**; /\* Optional; The type of maxValue, see values below.  
Defaults to 1 for CFVO\_MAX.e.g. 1 \*/   
**$maxValue**; /\* Optional; The numeric value for maximum.  
Defaults to 0.e.g. 0 \*/   
**$StopIfTrue**) /\* Optional; If true, no rules with lower priority may be applied over this rule, when this rule is true.  
Defaults to false.e.g. false \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| BookRef | The reference number for the workbook. | $ref |  |
| ConditionalFormattingRef | The reference number for the conditional formatting. | $ConditionalFormatting |  |
| minColor | the color for minimum |  |  |
| maxColor | the color for maximum |  |  |
| minType | the type of minValue, see values below.   Defaults to 0 for CFVO\_MIN. | 0 | Optional |
| minValue | The numeric value for minimum.   Default is 0. | 0 | Optional |
| maxType | The type of maxValue, see values below.   Defaults to 1 for CFVO\_MAX. | 1 | Optional |
| maxValue | The numeric value for maximum.   Defaults to 0. | 0 | Optional |
| StopIfTrue | If true, no rules with lower priority may be applied over this rule, when this rule is true.   Defaults to false. | false | Optional |

### Result

Returns OK or error.

### Description

Adds a conditional formatting rule that creates a gradated 2-color scale on the cells.  
Possible values for minType and maxType parameters:  
| Name | Value | Description |
|---|---|---|
| CFVO\_MIN | 0 | indicates that the minimum value in the range shall be used as the minimum value for the gradient |
| CFVO\_MAX | 1 | indicates that the maximum value in the range shall be used as the maximum value for the gradient |
| CFVO\_FORMULA | 2 | the minimum/midpoint/maximum value for the gradient is determined by a formula |
| CFVO\_NUMBER | 3 | indicates that the minimum/midpoint/maximum value for the gradient is specified by a constant numeric value |
| CFVO\_PERCENT | 4 | value indicates a percentage between the minimum and maximum values in the range shall be used as the minimum/midpoint/maximum value for the gradient |
| CFVO\_PERCENTILE | 5 | value indicates a percentile ranking in the range shall be used as the minimum/midpoint/maximum value for the gradient |

### Examples

Add conditional format to color cells based on value:

 Set Variable \[ $[CF](CF.md) ; Value: MBS ("[XL.Sheet.AddConditionalFormatting](XLSheetAddConditionalFormatting.md)"; $book ; $sheet ) \]  
Set Variable \[ $r ; Value: MBS ("[XL.ConditionalFormating.AddRange](XLConditionalFormatingAddRange.md)"; $book ; $[CF](CF.md); 3; 10; 2; 2) \]  
Set Variable \[ $r ; Value: MBS ("XL.ConditionalFormating.Add2ColorScaleRule"; $book ; $[CF](CF.md); MBS ( "[XL.Color.Pack](XLColorPack.md)"; $book ; 255; 133; 40 ); MBS ( "[XL.Color.Pack](XLColorPack.md)"; $book ; 255; 239; 156 )) \]  
### See also

- [XL.Color.Pack](XLColorPack.md)
- [XL.ConditionalFormating.Add2ColorScaleFormulaRule](XLConditionalFormatingAdd2ColorScaleFormulaRule.md)
- [XL.ConditionalFormating.Add3ColorScaleFormulaRule](XLConditionalFormatingAdd3ColorScaleFormulaRule.md)
- [XL.ConditionalFormating.Add3ColorScaleRule](XLConditionalFormatingAdd3ColorScaleRule.md)
- [XL.ConditionalFormating.AddAboveAverageRule](XLConditionalFormatingAddAboveAverageRule.md)
- [XL.ConditionalFormating.AddOpStrRule](XLConditionalFormatingAddOpStrRule.md)
- [XL.ConditionalFormating.AddRange](XLConditionalFormatingAddRange.md)
- [XL.ConditionalFormating.AddTimePeriodRule](XLConditionalFormatingAddTimePeriodRule.md)
- [XL.ConditionalFormating.AddTopRule](XLConditionalFormatingAddTopRule.md)
- [XL.Sheet.AddConditionalFormatting](XLSheetAddConditionalFormatting.md)

### Example Databases

- [XL/Conditional Formatting](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XL/Conditional%20Formatting.shtml#2ScriptAnchor_)

### Blog Entries

- [Conditional Formatting in Excel exports from FileMaker](https://www.mbsplugins.de/archive/2024-04-08/Conditional_Formatting_in_Exce/monkeybreadsoftware_blog_filemaker)

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

  
[XL.ConditionalFormating.Add2ColorScaleFormulaRule](XLConditionalFormatingAdd2ColorScaleFormulaRule.md) - [XL.ConditionalFormating.Add3ColorScaleFormulaRule](XLConditionalFormatingAdd3ColorScaleFormulaRule.md)

[HTML Version](XLConditionalFormatingAdd2ColorScaleRule.shtml)