-1

The code copies data from cell M4 and to cell L45, which is good but if I change the date in M4 and run the script it will overwrite cell L45 with the new info instead of copying to the next blank row below (cell L46) What is the adjustment needed and where would it go in the script

Here is code:

function moveValuesOnly() {

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var source = ss.getRange('M4');
 source.copyTo(ss.getRange('L45'), {contentsOnly: true}); 
Cooper
  • 59,616
  • 6
  • 23
  • 54

1 Answers1

0

This function will append any changes in 'M4' to the bottom of column L.

function onEdit(e) {
  var sh=e.range.getSheet();
  if(sh.getName()!='Sheet1') {return;};//edit Sheet name for your requirements
  if(e.range.getA1Notation()=='M4') {
    e.range.getSheet().getRange(getColumnHeight(12,sh,e.source) + 1,12).setValue(e.value);
  }
}

function getColumnHeight(col,sh,ss){
  var ss=ss || SpreadsheetApp.getActive();
  var sh=sh || ss.getActiveSheet();
  var col=col || sh.getActiveCell().getColumn();
  var rg=sh.getRange(1,col,sh.getLastRow(),1);
  var vA=rg.getValues();
  while(vA[vA.length-1][0].length==0){
    vA.splice(vA.length-1,1);
  }
  return vA.length;
}
Cooper
  • 59,616
  • 6
  • 23
  • 54