I want cell J2:K2
to be cleared ONLY when value in I1
changes.
I have the following script so far :
function onEdit(e) {
if (e.range.getA1Notation() === 'i1') {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1').getRange('j2:k2').clear()
}
}
I thought onEdit
would only fires up when I1
is changed however range J2:K2
keeps getting cleared when I try to write values in either J2
or K2
. Can someone please help me?
Simple fix. This works for me:
The problem was your
if
statement condition was not getting met. This is because.getA1Notation()
returns a string description of the range which needs to be exact. Replacingi1
withI1
fixes the problem.Hope this helps!