在电子表格之间复制数据 - "错误范围高度线21和#34;

时间:2016-07-05 08:46:56

标签: excel-vba vba excel

我有2个电子表格我有我的主电子表格和我的来源我想要复制行A-G并将其粘贴在主表格中,但它说我有不正确的高度范围

  

"incorrect range height line 21"

function myFunction() {
  // Get Spreadsheets
  var source = SpreadsheetApp.openById("1nqHrgEEYdiHmgfyIhpoFvG7iroDXWLhGPp1w_NJHI8s");
  var target = SpreadsheetApp.openById("1Gw3PH9f3CCKqjurLFQMDNSO_CBB3Q7m3JXbaQk-wZKc");

  // Set Sheets
var source_sheet = source.getSheetByName("Meeting");
var target_sheet = target.getSheetByName("Team A");

// Get target last row
var last_row = target_sheet.getLastRow();

// Set Ranges
var source_range = source_sheet.getRange("A1:G50");
var target_range = target_sheet.getRange("A"+(last_row+1)+":G"+(last_row+1));

  // Fetch values
  var values = source_range.getValues();

  // Save to spreadsheet
  target_range.setValues(values);
}

1 个答案:

答案 0 :(得分:1)

您尝试复制50行并将其粘贴到一行中。

var source_range = source_sheet.getRange("A1:G50");
var target_range = target_sheet.getRange("A"+(last_row+1)+":G"+(last_row+1));

尝试

var source_range = source_sheet.getRange("A1:G50");
var target_range = target_sheet.getRange("A"+(last_row+1)+":G"+(last_row+51));