PASTE INTO NEXT EMPTY ROW

2,243 views
Skip to first unread message

Picloan Limited

unread,
Apr 3, 2022, 12:41:45 AM4/3/22
to Google Apps Script Community
Dear sir, I have been trying to solve a problem but I could not. The below script is to copy from sheet and paste to other sheet. it works well but I am trying to make it to paste into next empty row with getLastRow()+1 but I did not know how to incorporate it to work. Please help me



function importRange(){

// Gather the source range values

const sourceSS = SpreadsheetApp.getActiveSpreadsheet();

const sourceRng = sourceSS.getRange("pank!I4:P20")

const sourceVals = sourceRng.getValues();

// Get the destiation sheet and cell location.

const destinationSS = SpreadsheetApp.openById('144K7R-h162rMKesnphSZoA');

const destStartRange = destinationSS.getRange(' kASTER3V!A1:G');

const destSheet = destStartRange.getSheet();

// Clear previous entries.

destSheet.clear();

// Get the full data range to paste from start range.

const destRange = destSheet.getRange(

destStartRange.getRow(),

destStartRange.getColumn(),

sourceVals.length,

sourceVals[0].length

);
// Paste in the values.

destRange.setValues(sourceVals);

SpreadsheetApp.flush();

};





Nigel Hunt

unread,
Apr 3, 2022, 3:28:08 AM4/3/22
to google-apps-sc...@googlegroups.com
I'm using this for something similar.

  var s = SpreadsheetApp.getActiveSpreadsheet()
  var ss = s.getSheetByName('Working')
  var LastWorkingRow = ss.getLastRow();

& also

  var ss = SpreadsheetApp.getActive().getSheetByName('Responses');
  ss.activate();
  var rangeToCopy = ss.getRange(StartRow1ss.getMaxRows(), 1);
  var ss = SpreadsheetApp.getActive().getSheetByName(subject);
  ss.activate();
  rangeToCopy.copyTo(ss.getRange(TargetRow1));
It should work for you if you set the sheet names to your own, set targetRow to LastWorkingRow
I hope this helps
Nigel

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/d9200cd5-d9f6-43c7-9036-9d994aec642bn%40googlegroups.com.

Igbekele Fanimo

unread,
Apr 11, 2022, 3:37:37 AM4/11/22
to Google Apps Script Community

Nigel Hunt, thanks for your assistance. God bless
Reply all
Reply to author
Forward
0 new messages