Diagnostic reference
The coordinates or dimensions of the range are invalid
Why getRange fails on a zero-length or zero-based range, and the empty-result guard that fixes the common case.
Updated September 12, 2026
Apps Script error
Exception: The coordinates or dimensions of the range are invalid.
What it means
A getRange call received a zero, negative, or out-of-bounds row, column, or size. The classic case is values.length equal to 0 because a filter returned nothing, turning getRange(2, 1, 0, 4) into a request for a zero-row range. Sheet coordinates are one-based, so row 0 or column 0 fails the same way.
Related error messages
- Exception: The number of rows in the range must be at least 1.
- Exception: The starting row of the range is too small.
Before and after
See the change before you make it.
function writeFiltered() {
const sheet = SpreadsheetApp.getActiveSheet();
const values = sheet.getDataRange().getValues().filter(r => typeof r[0] === 'number' && r[0] > 100);
sheet.getRange(2, 1, values.length, 3).setValues(values);
}function writeFiltered() {
const sheet = SpreadsheetApp.getActiveSheet();
const values = sheet.getDataRange().getValues().filter(r => typeof r[0] === 'number' && r[0] > 100);
if (values.length === 0) return;
sheet.getRange(2, 1, values.length, values[0].length).setValues(values);
}How to fix it
- Return before getRange when the filter produces no rows.
- Use one-based row and column coordinates.
- Size a nonempty destination range from the filtered array.
What stays with you
- Decide whether an empty result should clear the destination instead of skipping the write.
- myFunction does not run the filter.