Google Sheets – Trigger onEdit When Specific Cells Selected

google sheetsgoogle-apps-scriptgoogle-apps-script-triggers

I can't seem to figure out how to get my script to trigger only on the edit of specific cells and on the current sheet. I've tried just about everything and it just refuses to run the script at all if I change anything.

I've created new variables to try and select the specific cells, then trigger with an if statement all to no avail. The script below is the only current version I have working which triggers should I edit anything anywhere.

Please someone help me out, I've no idea what I've done wrong.

Edit: Updated the code I've been trying… Still not doing anything.

function onEdit(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var r  = sheet.getRange("D11");

if (r == 'Hide'){

  r.hideRows(11);

}}

Best Answer

Add getValue() to var r = sheet.getRange("D11");. The resulting code line is:

var r  = sheet.getRange("D11").getValue();

The above because getRange returns Range object which not return directly it's value/values.

Also replace r.hideRows(11); by sheet.hideRows(11);

For further details checkout https://developers.google.com/apps-script/guides/sheets