I have developed a Google sheet that has been working well over the past 2 years. Now, it has suddenly stopped functioning, providing the following error: "SWITCH has mismatched range sizes. Expected row count: 1, column count: 1. Actual row count: number_of_rows_in_sheet
, column count: 1."
Essentially the sheet contains a list of items that need to be checked at a certain interval (J=daily, M=monthly, S=semesterly, A=annually). The user checking the item ticks a checkbox, which causes an onEdit script to run, updating the date of lastChecked to today. Based on the interval, a formula calculates the deadline for nextCheck. This formula is in an ArrayFormula for the entire column.
As said, the system worked until a couple of weeks ago, and it still works when not using ArrayFormula, but I would prefer to work with ArrayFormula (easier for the user to add new rows).
A functional copy is available here. Sheet A is with ArrayFormula, B without, and C/D are empty but normally follow the A/B structure.
The error comes from the cell containing this formula (cell G2):
=ArrayFormula(IF(E2:E="","", SWITCH(D2:D, "A", DATE(YEAR(E2:E)+IF(C2:C="",1,C2:C),MONTH(E2:E),DAY(E2:E)), "M", DATE(YEAR(E2:E),MONTH(E2:E)+IF(C2:C="",1,C2:C),DAY(E2:E)), "S", DATE(YEAR(E2:E),MONTH(E2:E)+IF(C2:C="",6,C2:C *6),DAY(E2:E)), "J", DATE(YEAR(E2:E),MONTH(E2:E),DAY(E2:E)+IF(C2:C="",1,C2:C)),"","")))
The code updating the timestamp:
function onEdit(e) { //On edit...
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const changedCell = e.range; //Saves the range of the modified cell.
const sheetName = sheet.getName();
const sheetsToWatch = ['A', 'B', 'C', 'D'];
if (sheetsToWatch.includes(sheetName)) {
if(changedCell.getColumn() === 6 && changedCell.isChecked()) { //If cell is in col 6 (F) and checked
let newDateRange = sheet.getRange(changedCell.getRow(), 5);
newDateRange.setValue(new Date()); //Set the current timestamp in column 5 (E) at the same row as modified cell
changedCell.uncheck(); //Remove checkmark from modified cell
}
}
}
This is my first post so let me know if I forgot any useful information. Thanks in advance.