Skip to main content

Modify

Modifies the current format condition with the specified parameters.

Syntax

expression.Modify(Type, Operator, Formula1, Formula2);

expression - A variable that represents a ApiFormatCondition class.

Parameters

NameRequired/OptionalData typeDefaultDescription
TypeOptionalXlFormatConditionTypeThe format condition type.
OperatorOptionalXlFormatConditionOperatorThe format condition operator.
Formula1Optionalstring | number | ApiRangeThe first formula.
Formula2Optionalstring | number | ApiRangeThe second formula.

Returns

ApiFormatCondition | null

Example

Update the condition of an existing formatting rule to use new criteria in a spreadsheet.

// How do I change what value or formula a conditional formatting rule checks for in a spreadsheet?

// Replace the trigger condition of a formatting rule without removing it from a spreadsheet.

let worksheet = Api.GetActiveSheet();

worksheet.GetRange("A1").SetValue("Sales Data");
worksheet.GetRange("A2").SetValue(30);
worksheet.GetRange("A3").SetValue(250);
worksheet.GetRange("A4").SetValue(150);
worksheet.GetRange("A5").SetValue(300);
worksheet.GetRange("A6").SetValue(40);

let dataRange = worksheet.GetRange("A2:A6");

let formatConditions = dataRange.GetFormatConditions();

let condition1 = formatConditions.Add("xlCellValue", "xlLess", "50");
condition1.SetFillColor(Api.CreateColorFromRGB(255, 0, 0));

worksheet.GetRange("C1").SetValue("Original formula:");
worksheet.GetRange("C2").SetValue(condition1.Formula1);

condition1.Modify("xlCellValue", "xlGreater", "200");

worksheet.GetRange("C4").SetValue("Modified formula:");
worksheet.GetRange("C5").SetValue(condition1.Formula1);