google spreadsheet - moveTo messing up cells outside the range -


im rearranging spreadsheet using google script. first sorting , moving rows within range end of sheet. everytime moveto function cells reference moved rows changed reflect new row numbers though cells outside range , should not modified. example if im moving cell b3 , have cell f4 =b3 when move b3 cell f4 changes whatever b3 now. tried locking =b$3 still didnt work. messes conditional formatting should in place entire column using "d2:e" , changes "d2:e109" or similar. clue whats going on?

function onedit(){   var sheet = spreadsheetapp.getactivespreadsheet().getactivesheet();   var allowedsheet = 1;   if(sheet.getindex() == allowedsheet) {     var editedcell = sheet.getactivecell();      var sortby = [1, 3, 2];     var triggercol = [1,2,3,10,11,12];     var rangestart = "a";     var rangeend = "e";     var tablerange = "a2:e";      if(triggercol.indexof(editedcell.getcolumn()) > -1) {        var range = sheet.getrange(tablerange);       range.sort([{column: sortby[0], ascending: true}, {column: sortby[1], ascending: false}, {column: sortby[2], ascending: true}]);        var indexofincome = find( sheet, 2, "income");       if( indexofincome > 0 ){         var overflowrange = sheet.getrange("a2:e" + (indexofincome - 1 ));         var lastrow = findfirstemptycell( sheet, 1 );         overflowrange.moveto(sheet.getrange("a" + ( lastrow )));          var fullrange = sheet.getrange(rangestart + indexofincome + ":" + rangeend);         fullrange.moveto(sheet.getrange(rangestart + "2"));       }     }   } }  function find( sheet, column, value ) {   var data = sheet.getrange(1, column, sheet.getmaxrows()).getvalues();   for( = 0; < sheet.getmaxrows(); i++ ){     if (data[i][0].tostring().indexof(value) > -1 ) {       return + 1;     }   }   return 0; }  function findfirstemptycell ( sheet, column ){   var data = sheet.getrange( 1, column, sheet.getmaxrows() ).getvalues();   for( = 0; < sheet.getmaxrows() ; i++ ){     if( data[i][0] == "" ){       return + 1;     }   }   return 0; } 

it's expected behaviour, moveto works cut (ctrl+x), while looking copy+paste delete original content, should copyto(newrange) associated clear(oldrange).


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -