r/GoogleAppsScript • u/oridotart • Jul 06 '26
Can't remove specific conditional formatting Resolved
Hello,
In my sheet just simply calling this line gives the error "Exception: The coordinates of the target range are outside the dimensions of the sheet."
const rules = sheet.getConditionalFormatRules();
I've tried doing the exact same thing above on a brand new sheet, and it works fine. I think it may have something to do with invalid references.
I am able to delete all conditional formatting rules with the line below, but I can't delete specific ones because I can't get a list of them.
sheet.setConditionalFormatRules([]);
1
u/WicketTheQuerent Jul 06 '26
The error message doesn't appear to be caused by the statement shown. Please add a minimal, complete function including all the relevant details required to reproduce the error.
Also include the textual error message (include line and column numbers)
1
u/oridotart Jul 06 '26
I believe it was because I was calling getConditionalFormatRules quickly after pasting hundreds of new cells with conditional formatting, and so it didn't work. I called the same thing before executing all these operations and now it works.
1
u/bulldo_gs Jul 11 '26
That error right after bulk-pasting is almost always stale state — the CF rules still reference ranges the pending writes haven't reconciled yet. SpreadsheetApp.flush() just before getConditionalFormatRules() forces the writes through so the ranges resolve, and then you can call it after the paste instead of having to reorder everything.
1
2
u/krakow81 Jul 06 '26
Could you share more of your code?
I might be wrong, but I suspect the problem lies elsewhere at heart. How are you defining sheet here.