0

I have 6 columns A-F.. I want to be able to copy them from one sheet to another automatically - That I am able to do. I am using .getLastRow() on the range, but in column D I have x references that are being seen by .getLastRow() - so it is copying lots of blank cells with references on column D. What I would like to do is modify my code so it will copy my range referencing column A (e.g. Column A,B,C,E&F have 5 rows, D still has x values, but only copy the data subject to .getLastRow on column A only).

I've spent hours working on it but I'm not having a lot of luck...

/** Transfer from one sheet to another **/

function transferData() {
  // references
  var logSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Log');
  var appendSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Archive');
  
  // Create range strings for the rows in Log and Archive sheets
  var logSheetRange = "Log!9:" + logSheet.getLastRow();
  var archiveLastRow = logSheet.getLastRow() + appendSheet.getLastRow();
  var archiveAppendRange = "Archive!" + (appendSheet.getLastRow() + 1) + ":" + archiveLastRow;
  
  // Get range of data to copy
  var destRange = logSheet.getRange(archiveAppendRange);
  
  // Copy to archive
  var sourceDataValues = logSheet.getRange(logSheetRange).copyTo(destRange);
  

  
  // Clear range arrays after transfer
  logSheet.getRangeList(['A9:A59', 'C9:H59', 'K9:L59']).activate()
  .clear({contentsOnly: true, skipFilteredRows: true});
  
  // Return to first empty cell
  logSheet.getRange('A9').activate();
  
};
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
vividillusion
  • 99
  • 1
  • 8
  • You spent hours working but you didn't see that a couple of hours ago another person posted a very similar question on how to specify the last row of a particular column: https://stackoverflow.com/questions/64766282/is-there-some-approaches-that-will-log-information-in-the-last-row-for-specific – Marios Nov 10 '20 at 11:46
  • So essentially you just want to find the last row of each column in your data range? @vividillusion – ale13 Nov 10 '20 at 12:04

0 Answers0