0

So essentially, I wanted to create a script that takes the data from a specific range on one sheet, and push it over to a master sheet, or as I've called it, "Perpetual". New tabs are created daily, and the specified range on these new tabs would need to be pushed over as well, when prompted. When I try to use the script, everyone works, except when the data is being pasted on the "Perpetual" page, the lines are pasting many rows apart, instead of pasting in the last empty row. I am extremely new to coding, and definitely need some pointers as to where I messed up.

 function onOpen(e) {
      var ui = SpreadsheetApp.getUi();
      // Or DocumentApp or FormApp.
      ui.createMenu('Push to Perpetual')
          .addItem('Push to Perpetual', 'Macro')
          .addToUi();
    }
      function Macro() {
      var s = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Extraction Log Perpetual")
      var s2 = SpreadsheetApp.getActiveSheet()
      var a=s.getLastRow()+1
      s2.getRange(3, 21, 5, 13).copyTo(s.getRange(a,1),SpreadsheetApp.CopyPasteType.PASTE_VALUES, false)
    };
1
  • It works for me.
    – Cooper
    Apr 10, 2020 at 20:06

1 Answer 1

0

If the data is getting pasted many rows down the actual row then it means that there is something else in that sheet which is resulting getLastRow() to skip to the end. What you could do is get the last row from column A.

var a=s.getRange("A:A").getValues().filter(function(item){return item != ""}).length+1;

Expanation You are getting all the values from column A, then filtering out cells that don't have any value. And then get the length of the array, add 1 so that you can get the next row.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.