Looking to highlight negative numbers in Excel using Power Automate?
Standard Power Automate actions can’t change font colors, but Office Scripts can. This post shares a simple script to automatically format negative numbers in red—a perfect solution for financial reports or data validation.
The Goal



In this post, I will try to specify the font color for these numbers: “Red for negative, Black for positive“.
Method: Use the setNumberFormat function
To specify Excel formats from Office Scripts, use the setNumberFormat function.



function main(workbook: ExcelScript.Workbook, numbers: number[]): void {
if (!numbers || numbers.length === 0) return;
const sheet = workbook.getActiveWorksheet();
// Define the vertical range starting from A1 based on the array length
const startCell = sheet.getRange("A1");
const writeRange = startCell.getResizedRange(numbers.length - 1, 0);
// Office Scripts uses a 2D array for setValues
const values: (number | string | boolean)[][] = numbers.map(n => [n]);
writeRange.setValues(values);
// Turn negative numbers red
writeRange.setNumberFormat("0;[Red]-0");
}
コメント