I have two Spreadsheets, A & B, and I am writing a script to merge them with customizations for each Business Unit.
Spreadsheet A contains a sheet "Calculations", with formula references to a sheet called "Materials", but it does not contain the Materials sheet.
I wrote the script to copy the "Materials" sheet from Spreadsheet B into Spreadsheet A.
var materialsSheet = spreadSheetB.getSheetByName("Materials");
materialsSheet.copyTo(spreadSheetA).setName("Materials");
However, the formulas on "Calculations" sheet in SpreadsheetA are still complaining "Materials" sheet not found. If I manually go into the Front End and simulate an edit, the values in the cells get updated.
I tried copying the formulas and pasting them back via Apps-Script, but it didn't work. Any suggestions on how to make it work?
var readRange = calcSheet.getRange(9,1,7,6);
readRange.copyTo(calcSheet.getRange(9,1,7,6));
Another line of thought: My guess is that "Materials" sheet is referenced internally by G-sheets using some reference id, not its name. How do I programmatically update the internal reference?
Update: My question was identified as a possible duplicate of another question, which uses "Indirect" in its formula. I don't use "Indirect" in my spreadsheet, which takes in the address as a String and returns a reference address. That is not the functionality I am looking for, so I cannot add it to my sheet formulas. I did try the suggested solution for that question (use IFERROR), but it didn't help either. I just get the null value returned in case of error.
flush()
? – Argyllflush
and see if it works? – Argyll