我正在尝试使用单元格A3的值作为变量来指定特定数组的确切大小。下面的代码不起作用,为什么?
A3是= COUNTA(B2:VF2)-1,其当前值为446
function RangeCopyToLog() {
var spreadsheet = SpreadsheetApp.getActive();
var destSheet = spreadsheet.getSheetByName("Xp Log");
var lastRow = destSheet.getLastRow();
var copyColEnd = destSheet.getRange('A3') + 1 //Problem is here
destSheet.insertRows(lastRow + 1,1);
destSheet.getRange(1,3,1,copyColEnd).copyTo(destSheet.getRange(34,3,1,copyColEnd), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
// destSheet.getRange('D1:D30').copyTo(destSheet.getRange(lastRow + 1,1), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, true);
// destSheet.getRange('D1:D30').clearContent();
};
出现的错误是:“无法将Range1转换为(类)。”
答案 0 :(得分:1)
.getRange()仅返回范围,而不返回值。更改此行
var copyColEnd = destSheet.getRange('A3') + 1
到
var copyColEnd = destSheet.getRange('A3').getValue() + 1