Why does my script only paste the correct copied cells on another page when the script is run from the page of the copied cells that are included in it?
I would like to copy cells from one page and paste them onto the main ("checklist") page, preferably from a button I assign the macro to on the main page. I automated the copying, inserting and shifting of the cells but it only pastes the correct range when the macro is run from the other page, not the main ("checklist") page. I have added a button onto the other page and it works fine when pressed, I just have to wait until it finishes running before I can go back to the main ("checklist") page. Any help why it doesn't run properly when run from the main ("checklist") page would be much appreciated!
Here is the code:
function main(workbook: ExcelScript.Workbook) {
let checklist = workbook.getWorksheet("Checklist");
let selectedSheet = workbook.getActiveWorksheet();
// Insert copied cells from B10:AU18 on selectedSheet to B4:AU12 on checklist.
checklist.getRange("B4:AU12").insert(ExcelScript.InsertShiftDirection.down);
checklist.getRange("B4:AU12").copyFrom(selectedSheet.getRange("B10:AU18"));
}