[英]Google Sheets Copy one Cell and paste into another Cell
I want to copy a number from a cell and paste it into another cell on the same sheet using a button.我想从一个单元格中复制一个数字并使用按钮将其粘贴到同一张表上的另一个单元格中。
The cell also has a formula so I only want the number to be taken, not the formula.该单元格也有一个公式,所以我只想取数字,而不是公式。 That uses a RANDBETWEEN.
那使用一个RANDBETWEEN。
But to also have the numbers continue to drop down a column but not on the last row.但也要让数字继续下降一列,而不是最后一行。
function copytest()
{var sheet2 = SpreadsheetApp.getActive().getSheetByName('A');
sheet2.getRange("B4").copyTo(sheet2.getRange(sheet2.getLastRow()+1,1,1,1),
{formatOnly:false , contentsOnly:true});
}
IMAGE: https://i.stack.imgur.com/Po1Sa.jpg图片: https://i.stack.imgur.com/Po1Sa.jpg
This function places the value in the next empty row at the bottom of the current column.这个 function 将值放在当前列底部的下一个空行中。
function copytest() {
const ss=SpreadsheetApp.getActive();
const sh=ss.getSheetByName('Sheet1');
const rg=sh.getActiveCell();
const col=rg.getColumn();
rg.copyTo(sh.getRange(getColumnHeight(col,sh,ss)+1,col),{formatOnly:false , contentsOnly:true});
}
Function to find the next empty row in a column Function 查找列中的下一个空行
function getColumnHeight(col,sh,ss){
var ss=ss||SpreadsheetApp.getActive();
var sh=sh||ss.getActiveSheet();
var col=col||sh.getActiveCell().getColumn();
const rcA=sh.getRange(1,col,sh.getLastRow(),1).getValues().reverse()
let s=0;
for(let i=0;i<rcA.length;i++) {
if(rcA[i][0].toString().length==0) {
s++;
}else{
break;
}
}
return rcA.length-s;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.