[英]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.