Kureelpa_Rat
Kureelpa_Rat

Reputation: 11

Office Script Loop Excel Automate

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

Upvotes: 0

Views: 4277

Answers (1)

Yutao Huang
Yutao Huang

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

Related Questions