简体   繁体   English

什么是计算最后一行并将单元格数据添加到新空白行的代码

[英]What is code to count last row and add cell data to new blank row

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代码将数据从单元格 M4 复制到单元格 L45,这很好,但是如果我更改 M4 中的日期并运行脚本,它将用新信息覆盖单元格 L45,而不是复制到下面的下一个空白行(单元格 L46)是否需要调整以及它会在脚本中的哪个位置

Here is code:这是代码:

function moveValuesOnly() {

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var source = ss.getRange('M4');
 source.copyTo(ss.getRange('L45'), {contentsOnly: true}); 

This function will append any changes in 'M4' to the bottom of column L.此函数会将“M4”中的任何更改附加到 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据单元格值添加行,在 A 列的最后一个数据下方 - Add Row based on cell value, Below the last data in column A 用于在表中添加行的Javascript代码将单元格中的数据复制到新行 - Javascript code for adding rows in a table copies the data in the cell to new row AspxGridview添加新行并保留最后一行的值 - AspxGridview Add new row and retain last row value Javascript 添加新行,然后在最后一行删除 - Javascript add new row with <tr> then remove at the last row 数据输入表,希望添加“新建单元格”按钮,以便每次单击都会生成一个新行 - Data entry table, looking to add “New cell” button to generate a new row per each time clicked 如何将数据值添加到适合的行/单元格 - How to add data value to footable row/cell 用新的传入数据反应添加新行 - react add new row with the new incoming data 在 Google 可视化中添加新的数据行 - Add new Data Row in Google Visualisation 在表中添加新行以使脚本不仅在第一行与新行中的元素连接时的方式是什么? - what is the way when add new row in table to make script connect with element in new row not only at first row? 在两列的每一行中的每个单元格中添加1,直到到达空白单元格-Google Spreadsheet - Add 1 to each cell in every row of two columns until a blank cell is reached - Google Spreadsheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM