at the moment I have a sheet that has a script that is time triggered, the script at the end of the day will copy sheets at the bottom of the target sheet, everytime I am trying to do targetSheet.getrange(1,1) 1; it's not converting range to int. can someone please help?
function copyData() {
var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = spreadSheet.getSheetByName('copiedPausingSheet');
let sourceRange = sourceSheet.getDataRange();
let sourceValues = sourceRange.getValues();
let rowCount = sourceValues.length;
let columnCount = sourceValues[0].length;
let targetSheet = spreadSheet.getSheetByName('collectivePausingData');
let lastrowCount = targetSheet.getLastRow() 1;
let targetRange = targetSheet.getRange(lastrowCount,1, rowCount,columnCount);
targetRange.setValues(sourceValues);
}
CodePudding user response:
Is that what you mean? Paste values on the top of the sheet.
function copyData() {
var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = spreadSheet.getSheetByName('copiedPausingSheet');
let sourceRange = sourceSheet.getDataRange();
let sourceValues = sourceRange.getValues();
let rowCount = sourceValues.length;
let columnCount = sourceValues[0].length;
let targetSheet = spreadSheet.getSheetByName('collectivePausingData');
targetSheet.insertRows(1,sourceValues.length);
let targetRange = targetSheet.getRange(1,1,sourceValues.length,sourceValues[0].length);
targetRange.setValues(sourceValues);
}
CodePudding user response:
Do you mean this?
function copyDataOnTop() {
var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = spreadSheet.getSheetByName('copiedPausingSheet');
let sourceRange = sourceSheet.getDataRange();
let sourceValues = sourceRange.getValues();
let targetSheet = spreadSheet.getSheetByName('collectivePausingData');
var targetValues = targetSheet.getDataRange().getValues();
var allValues = [...sourceValues, ...targetValues];
let targetRange = targetSheet.getRange(1,1,allValues.length,allValues[0].length);
targetRange.setValues(allValues);
}