0

I'm trying to write a script that finds data in a sheet dynamically (the dimensions of the table need to be flexible in both axis) and then updates the source data range for an existing chart on another sheet (so that my users don't need to set up the styling themselves).

Below is my script so far. Everything works apart from the final line where Excel Online gives me the error:

"Line 10: Chart setData: You cannot perform the requested operation"

function main(workbook: ExcelScript.Workbook)
{
  let selectedSheet = workbook.getWorksheet("Enter data in this sheet");
  // Add a new table at used range on selectedSheet
  let range = selectedSheet.getUsedRange();
  if(selectedSheet.getTables().length == 0)
  {
  let newTable = workbook.addTable(range, true);
  }
  workbook.getWorksheet("The Chart").getChart("Chart 1").setData(range);
}

The worksheet names are correct and so is the chart name as far as I can see: screenshot of excel online showing chart and worksheet names

Mookmac
  • 11
  • 3

1 Answers1

1

Answer found; the chart was on a protected sheet which did not allow editing of objects. Updating the protection to allow all users to edit objects has resolved the issue.

Mookmac
  • 11
  • 3