简体   繁体   English

将单元格复制并粘贴到特定列谷歌表格中的第一个空行

[英]Copy and Paste a Cell to First Empty Row in Specific Column google sheets

I am trying to copy and paste values of cell J3 from Activity Report to the first empty cell in column L.我正在尝试将单元格 J3 的值从活动报告复制并粘贴到列 L 中的第一个空单元格。

The cell to copy is fixed, but the cell to paste in is variable.要复制的单元格是固定的,但要粘贴的单元格是可变的。

So far the code I am using has only been able to copy the values from J3 to the last row of column L instead of the first blank row from the top.到目前为止,我使用的代码只能将值从 J3 复制到 L 列的最后一行,而不是从顶部开始的第一个空白行。 Any attempt to manipulate the destination has been unsuccessful.任何操纵目的地的尝试都没有成功。 I was able to have it paste at the top but it kept overwriting the same cell.我能够将它粘贴在顶部,但它一直覆盖同一个单元格。

   function copyData() {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sName = ss.getSheetName();

if (sName == 'Activity Report'){
  var source = ss.getRange("Activity Report!J3");
  var destSheet = ss.getSheetByName("Activity Report");
  var lastRow = destSheet.getLastRow();

  var destination = destSheet.getRange("L"+lastRow);
  destination.activate();
  source.copyTo(destination, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  };
}

Thanks in advance!提前致谢!

Copying data to first empty cell in Columnn L将数据复制到 Column L 中的第一个空单元格

Copy value from J3 to bottom of column L将值从J3复制到 L 列底部

function copyData() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Activity Report');
  sh.getRange(sh.getLastRow()+1,12).setValue(sh.getRange(3,10).getValue());
}

Try this:试试这个:

This will put it into the very first empty cell in column L which could be the lastRow()+1 if there are no blanks.这会将其放入 L 列的第一个空单元格中,如果没有空格,则该单元格可能是 lastRow()+1 。

function runOne() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Activity Report');
  var f=false;
  var L=sh.getRange(1,12,sh.getLastRow()+1,1).getValues().map(function(r,i){if(!f && r[0].toString().length==0){f=true;return i+1;}else{return '';}}).filter(function(e){return e;});
  sh.getRange(L,12).setValue(sh.getRange(3,10).getValue());
}

This uses reduce:这使用减少:

If nothing else it's a bit simpler.如果不出意外,它会更简单一些。

function copyData() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Activity Report');
  var f=false;
  var L=sh.getRange(1,12,sh.getLastRow()+1,1).getValues().reduce(function(a,r,i){if(!f && r[0].toString().length==0){f=true;return a + i;}return a;},1);
  sh.getRange(L,12).setValue(sh.getRange(3,10).getValue());
}

Array.map 数组.map

Array.filter 数组.filter

Array.reduce 数组.reduce

暂无
暂无

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

相关问题 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 sheets macro to paste row at first empty row 复制到特定行的第一个空单元格 - Copy to first empty cell of a specific row 将 static 值粘贴到列中,除非特定单元格在谷歌表格中为空 - Paste the static value in the column besides if the particular cell is empty in google sheets 复制并粘贴到特定行 Google 表格宏中的下一个可用列 - copy and paste to next available Column in a certain Row Google Sheets Macro 复制并粘贴到Google特定列中的下一个可用行 - copy and paste to next available row in a certain column google sheets Google Sheets Scripts - 对于范围内的每个单元格,获取单元格具有特定值的行号,将行复制到范围内的第一个空白行 - Google Sheets Scripts - For each cell in range, get row number where cell has specific value, copy row to first blank row in range 粘贴到特定列-Google表格 - Paste into a Specific Column - Google Sheets 在谷歌表格中的 C 列中的值复制/粘贴或插入/编辑整行时插入时间戳,仅插入空白单元格 - Insert timestamp when value copy/paste or inserts/edits whole row in Column C in google sheets, only insert to blank cell 谷歌表格 - 复制单元格 -> 清除单元格 -> 粘贴单元格 - Google Sheets - Copy Cell -> Clear Cell -> Paste Cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM