Type of Edition (Cell or Range) - OnEdit

11 views
Skip to first unread message

Sandra Patricia Perdigon Cortes

unread,
Nov 4, 2024, 2:56:37 AM (9 days ago) Nov 4
to Google Apps Script Community
Hello,
This is my scenario:
I have a Google Sheet with 4 dropdowns (all depended one from each other) and I need to clean the next ones when one is edited... this I already have it.

However it shouldn't work always, just when the user changes the value manually for a specific one. If the user copies and pastes the values  from another file (the 4 at same time) it shouldn't clean them.

This is the code I have so far... to control this I should know if it was edited a single cell or a range of cells, do you know how to know that?

function installedOnEdit(e) {

  if(e.range.rowStart!=1) {    
    // create dynamic and filtered dropdowns
    dropdown(e);
   
    var s = SpreadsheetApp.getActive();
    var r = s.getActiveCell();
 
    // clean depended dropdowns when a single cell is edited
   
    if( r.getColumn() == 1 ) {
      r.offset(0, 1).setValue('');
      r.offset(0, 2).setValue('');
      r.offset(0, 3).setValue('');
    }
    if( r.getColumn() == 2 ) {
      r.offset(0, 1).setValue('');
      r.offset(0, 2).setValue('');
    }
    if( r.getColumn() == 3 ) {
      r.offset(0, 1).setValue('');  
    }
  }
 }

Or maybe you have a best way to do it.
I appreciate your help.
Regards.


The information contained in this e-mail may be confidential. It has been sent for the sole use of the intended recipient(s). If the reader of this message is not an intended recipient, you are hereby notified that any unauthorized review, use, disclosure, dissemination, distribution or copying of this communication, or any of its contents, is strictly prohibited. If you have received it by mistake please let us know by e-mail immediately and delete it from your system. Many thanks.

 

La información contenida en este mensaje puede ser confidencial. Ha sido enviada para el uso exclusivo del destinatario(s) previsto. Si el lector de este mensaje no fuera el destinatario previsto, por el presente queda Ud. notificado que cualquier lectura, uso, publicación, diseminación, distribución o copiado de esta comunicación o su contenido está estrictamente prohibido. En caso de que Ud. hubiera recibido este mensaje por error le agradeceremos notificarnos por e-mail inmediatamente y eliminarlo de su sistema. Muchas gracias.


Reply all
Reply to author
Forward
0 new messages