Skip to main content

GetAppliesTo

Returns the range of cells to which the current conditional formatting rule applies.

Inherited from ApiFormatCondition.GetAppliesTo.

Example

Read the cell range that a conditional formatting rule covers in a spreadsheet.

// How do I find out which cells a conditional formatting rule is applied to in a spreadsheet?

// Identify the target area of a formatting condition to verify it targets the correct cells in a spreadsheet.

let worksheet = Api.GetActiveSheet();

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

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

let formatConditions = dataRange.GetFormatConditions();

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

let appliedRange = condition1.GetAppliesTo();

worksheet.GetRange("C1").SetValue("Rule applies to:");
worksheet.GetRange("C2").SetValue(appliedRange.GetAddress());