'How to save on the next row from one existing data of copied google spreadsheet to another google spreadsheet using google apps script?
I have this dilemma where i recorded a macro to copy a row to another sheet but so happens every time i run the macro it will always save on the same row. what can I add to this script in order for the macro to save it after the previously saved data?
Current Code:
function SAVING2() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A2:O2').activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Audit RAW'), true);
spreadsheet.getRange('A2').activate();
spreadsheet.getRange('\'audit dump\'!A2:O2').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
What I wish to accomplish:
For the macro to save the next set of data after the previous
Your help would be greatly appreciated
Solution 1:[1]
In your script, from spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Audit RAW'), true); and spreadsheet.getRange('A2').activate();, the destination range is always "A2" of "Audit RAW" sheet. I think that this is the reason of your issue. In your situation, how about the following modification?
Modified script:
function SAVING2() {
var spreadsheet = SpreadsheetApp.getActive();
var src = spreadsheet.getRange('\'audit dump\'!A2:O2');
var dstSheet = spreadsheet.getSheetByName("Audit RAW");
var dst = dstSheet.getRange(dstSheet.getLastRow() + 1, 1);
src.copyTo(dst, SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
}
- In this modification, the destination range is set as the next row of the last row. By this, the copied value is appended to the destination sheet.
Reference:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tanaike |
