I have been trying to copy the last non empty cell from Sheet1 Column A and paste that cell into the last empty cell of the Sheet2 Column D.
that code should work whenever Sheet1 ColA is edited or update new value.
But an error The coordinates of the target range are outside the dimensions of the sheet. is appearing. Any help will be appreciated.
function myFunction() {
const sheetName1 = "sheet1";
const sheetName2 = "sheet2";
const sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName1);
const sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName2);
const lastRow1 = sheet1.getLastRow();
const lastRow2 = sheet2.getLastRow();
sheet1.getRange("A" + lastRow1).copyTo(sheet2.getRange("D" + (lastRow2 + 1)));
}