Home > Net >  When trying to run onEdit(e) : - TypeError: Cannot read property 'range' of undefined onEd
When trying to run onEdit(e) : - TypeError: Cannot read property 'range' of undefined onEd

Time:11-06

This is the code I am trying to run with no success:-

function onEdit(e) {
  
  
 if (e.range.getA1Notation == "c19") {
 if (e.range.getValue == true) {
 
 var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('2:19').activate();
  spreadsheet.getActiveSheet().hideRows(spreadsheet.getActiveRange().getRow(), spreadsheet.getActiveRange().getNumRows());
   spreadsheet.getRange('1:1').activate();
  spreadsheet.getActiveSheet().showRows(1, 199);
  spreadsheet.getRange('58:199').activate();
  spreadsheet.getActiveSheet().hideRows(spreadsheet.getActiveRange().getRow(), spreadsheet.getActiveRange().getNumRows());
  spreadsheet.getRange('2:19').activate();
  spreadsheet.getActiveSheet().hideRows(spreadsheet.getActiveRange().getRow(), spreadsheet.getActiveRange().getNumRows());
  spreadsheet.getRange('A1:M1').activate();
}
 }
}

Please can you help? I am not very good with syntax so I am sure it is a simple adjustment that I need.

Many thanks in advance, Marilyn

In Google Sheets I am trying to run a macro that will hide rows when the value of a cell is TRUE

There will be more rows to unhide and hide in the same routine, but I am just trying to get the first bit to work.

CodePudding user response:

This is what you code does:

function onEdit(e) {
  const sh = e.range.getSheet();
  if(sh.getName() == "Your Sheet Name" && e.range.columnStart == 3 && e.range.rowStart == 19 && e.value == "TRUE") {
    sh.hideRows(2,18);
    sh.showRows(1,199);
    sh.hideRows(58,142);
    sh.hideRows(2,18);
  }
}

CodePudding user response:

"Because onEdit triggers only fire for user edits. – Cooper"

How can I run it in copy paste?

  • Related