I am working on an Excel workbook that will contain a sheet for each day, with a log of various times for work, equipment failures, etc.
This one sheet, MASTER, should be copied to 365 (366 for leap years) sheets, each named by date, from 01-01-2022 to 31-12-2022.
In one cell of each sheet, the date should be entered.
Now, I have recorded a macro that selects a sheet, copies this and moves it to the end of the row, adds the date in the appropriate cell and then renames the sheet to a date.
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Duplicate worksheet
let mASTER__2_ = selectedSheet.copy(ExcelScript.WorksheetPositionType.before, selectedSheet);
// Reorder mASTER__2_
mASTER__2_.setPosition(3);
// Rename worksheet to "01-01-2022"
mASTER__2_.setName("01-01-2022");
let _01_01_2022 = workbook.getWorksheet("01-01-2022");
// Set range Q1:T2 on _01_01_2022
_01_01_2022.getRange("Q1:T2").setValue("01-01-2022");
}
What I need now is the format for the loop to repeat for each day in a given year, and how to set a variable, e.g. "myDate", that will increase with one day per iteration of the loop, instead of the hardcoded date in the example above.
While we could work in a routine to copy the master sheet at the end (or beginning) of each work day, I would like to have the full year ready in one workbook at once.