Using capture.offset

0

Hello, the following script checks if a column has changed, and then it copies a formula into the corresponding cell from another column. It's working. However, as it only copies a string, ie = IF (COUNTA (E3) = 0; ";; E3-TODAY (), the same operation is performed on all cells. How can I achieve the effect that if I change the cell it copies the formula but updates in its current position? For example, if you are in the cell
E10, it updates to = IF (COUNTA (E10) = 0; "; E10-TODAY (). The script is below:

function onEdit() {
 var ActiveSheet= SpreadsheetApp.getActiveSheet();
   var capture = ActiveSheet.getActiveCell();
    for (var i=0;i<1000;i++){
   if(capture.getColumn() == 5 ) {
     var add = capture.offset(0, 4);

       add.setValue('=IF(COUNTA(E3)=0;"";E3-TODAY())');
   }}}
    
asked by anonymous 20.05.2018 / 13:28

0 answers