简体   繁体   English

谷歌表格复制一个单元格并粘贴到另一个单元格

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

相关问题 谷歌表格 - 复制单元格 -&gt; 清除单元格 -&gt; 粘贴单元格 - Google Sheets - Copy Cell -> Clear Cell -> Paste Cell Google Sheets + Apps Scripts,从一个工作表复制/粘贴到另一个工作表,但粘贴到特定列 (B) 中的第一个空单元格 - Google Sheets + Apps Scripts, Copy/Paste from one sheet to another, but Paste into first empty cell in specific column (B) 将一个单元格复制到Google表格中的相邻单元格 - Copy one cell to adjacent cell in Google Sheets onEdit 特定单元格将数据从一个谷歌表格复制到另一个 - onEdit specific cell copy data from one google sheets to another 将单元格复制并粘贴到特定列谷歌表格中的第一个空行 - Copy and Paste a Cell to First Empty Row in Specific Column google sheets Google 表格中的事件变量不会获取我从另一个单元格复制和粘贴值的单元格的值 - Event variable in Google sheets doesn't fetch a value of the cell to which I do copy and paste a value from another cell 谷歌表格我可以使用超链接从一个单元格跳转到另一个单元格并将数据复制到另一个单元格吗 - Google sheets can I use hyperlink to jump from one cell to another and copy data to the other cell Google表格可以将一个单元格更改为另一个单元格 - Google Sheets change one cell from another GAS Google Script - 如何复制值并粘贴到另一个单元格 - GAS Google Script - How copy value and paste in another Cell Google 表格脚本 - 将粘贴值从一列复制到另一列 - Google sheets script - copy paste values from one column to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM