Reputation: 11
Quick question I have around loops for office script in excel
I want to loop the below code/formatting changes across specific worksheets. I want to be able to select the sheets based on the worksheet name eg. Worksheet name starts with "XYZ", change this formatting etc.
Below is a small example, I have attempted to make this work but it comes up with an error.
Upvotes: 0
Views: 4277
Reputation: 1571
Here is a sample script that loops through all the worksheets, finds those with name starting with "XYZ", then fills column H with blue.
function main(workbook: ExcelScript.Workbook) {
workbook.getWorksheets()
.filter(sheet => sheet.getName().startsWith("XYZ"))
.forEach(sheet => {
sheet.getRange("H:H").getFormat().getFill().setColor("blue");
});
}
Upvotes: 2