0

so I have added coding to copy information from one sheet to another, but it puts it in at line 2000 +, not in the next available line. How can I change it? It needs to go into the next available line, not at the bottom. I have used .getLastRow() how can I go further?

  • I would suggest you post your code. Otherwise we are just guessing. – TheWizEd Aug 15 '22 at 15:26
  • If there are formulas in adjacent columns, that may be the reason... Cooper's answer below should help, but try to post a practical example of your issue, so that it gets easier for folks to help. – onit Aug 15 '22 at 17:35
  • Duplicate of https://stackoverflow.com/questions/46883862/arrayformula-is-breaking-the-getlastrow-funtion-possible-workarounds https://stackoverflow.com/questions/17632165/determining-the-last-row-in-a-single-column – TheMaster Aug 15 '22 at 17:44

1 Answers1

1

Last Available Empty Line or first empty line above the end

function lastavailableline() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const shsr = 2;
  const vs = sh.getRange(shsr, 1, sh.getLastRow() - shsr + 1, sh.getLastColumn()).getValues();
  let mts = [];
  vs.forEach((r,i) => {
    if(r.every(e => e == "")) {
      mts.push(i + shsr);
    }
  })
  Logger.log(mts.reverse()[0]);
}

It sounded to me that this is what the op was asking.

Cooper
  • 59,616
  • 6
  • 23
  • 54