0

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.

enter image description here

Yutao Huang
  • 1,503
  • 1
  • 13
  • 25
Kureelpa_Rat
  • 11
  • 1
  • 5

1 Answers1

2

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");
    });
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Yutao Huang
  • 1,503
  • 1
  • 13
  • 25