简体   繁体   English

将范围从最后一行复制到新工作表

[英]Copy a range from last row to new sheet

I want to take the last response from a Google Form and copy it to the same range on another sheet. 我想从Google表单中获取最新回复,然后将其复制到另一张纸上的相同范围内。

The second sheet has some data in columns A & B (a login and password) that I want to assign as somebody completes the registration form. 第二张纸在A和B列(登录名和密码)中有一些数据,我想在完成填写注册表时分配给他们。

I want the data from column B to H from the form response sheet to be copied to column C to I on the sheet that contains the login/password columns when a response is received. 我希望从表单响应表中的B列到H的数据在收到响应时被复制到包含登录名/密码列的表的C列到I列。

I know I am missing the code to take the range from the last row, but I know NO coding at all and my current script is compiled from things I've found around the web and the reference material. 我知道我缺少从最后一行获取该范围的代码,但我完全不知道编码,而我当前的脚本是根据我在网络上找到的内容和参考资料编译而成的。

Any advice would be greatly appreciated. 任何建议将不胜感激。

function onEdit(e) {


  var spreadsheet = SpreadsheetApp.openById("sheetid");
  var sheet = spreadsheet.getSheets()[0];


  var lastrow = sheet.getLastRow();
  var range = sheet.getRange(2,2,1,7);
  values = range.getValues();

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var SSsheet = ss.getSheets()[1];


  var ssRange = SSsheet.getRange(2,3,1,7);
  ssRange.setValues(values);

  }

Try using copyTo(destination) . 尝试使用copyTo(destination) It copies the data from a range of cells to another range of cells. 它将数据从一个单元格区域复制到另一个单元格区域。 Both the values and formatting are copied. 值和格式均被复制。

 // The code below will copy the first 5 columns over to the 6th column.
 var sheet = SpreadsheetApp.getActiveSheet();
 var rangeToCopy = sheet.getRange(1, 1, sheet.getMaxRows(), 5);
 rangeToCopy.copyTo(sheet.getRange(1, 6));
 }

You can also try using copyValuesToRangecopyValuesToRange . 您也可以尝试使用copyValuesToRangecopyValuesToRange

For additional code samples, you may also refer to this forum . 有关其他代码示例,您也可以参考此论坛

function onEdit(e) {

var spreadsheet = SpreadsheetApp.openById("ID");
var sheet = spreadsheet.getSheets()[0];
var lastRow = sheet.getLastRow();
var range = sheet.getRange("A"+(lastRow)+":G"+(lastRow));
var values = range.getValues();


var ss = SpreadsheetApp.getActiveSpreadsheet();
var SSsheet = ss.getSheets()[1];
var getRow = SSsheet.getLastRow() + 1;
var ssRange = SSsheet.getRange(getRow, 1, values.length, values[0].length);
ssRange.setValues(values);

Try with this, this code copies the last value you want from a certain range and pastes it in the last available row of the other sheet. 尝试使用此代码,此代码将从特定范围复制所需的最后一个值,并将其粘贴到另一张纸的最后一个可用行中。
The code it's the same only in the place where you are going to copy it, specify it to be the size of what I want to copy. 它的代码仅在要复制的地方相同,将其指定为我要复制的大小。 I hope it helps you :D 希望对您有帮助:D

暂无
暂无

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

相关问题 如何将范围从母版表复制到另一张表的最后一行(另一张表名称= Mastersheet Z1中的单元格值) - How to copy a range from a mastersheet to the last row of another sheet (Another sheet name = cell value in Mastersheet Z1) 从1张纸中复制值并将值设置到另一张纸的最后一行 - Copy values from 1 sheet and set values to last row of another sheet 将谷歌工作表中的数据复制到另一个谷歌工作表的最后一行 - Copy data from a google sheet to the last row in another google sheet 如何从谷歌工作表复制最后一行并复制到其他谷歌工作表的最后一行 - How to copy last row from google sheet and copy to last row of other google sheet 从范围复制单元格值并将其粘贴到另一个工作表的单行中 - To copy Cell values from a range and paste it in a single row of another sheet 从最后一行复制特定的列数据并粘贴到另一个工作表 - Copy specific Columns data from Last Row and paste to another sheet 从一张纸到另一张纸的范围复制脚本,删除复制的范围并从第三张纸粘贴新公式 - Script for copy range from a sheet onto another, delete copied range and paste new formulas from a third sheet 如何将范围从一个工作表复制到另一工作表的范围,然后重复复制到下一行 - How to copy a range from one sheet to a range in another sheet, then repeat copying to the next row down 尝试将数据从源 Google 工作表的最后一行复制并粘贴到目标工作表的最后一行时似乎出现错误 - Seem to be getting an error when trying to copy and paste data from last row of the source google sheet to the target sheet last row Google Appscript:将表格中的数据复制到最后一行中的另一张表格并清除表格 - Google Appscript: Copy Data from a Form Sheet to Another Sheet in Last Row and Clear Form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM