Ralu Carmichael
Ralu Carmichael

Reputation: 15

Google Sheets: Copy a cell into the first blank cell in a column

I need to copy from cell A2, which is a forever changing formula, because it captures =NOW() and copy that as value in first blank cell in column B. I have tried Last row, but becasue I do have data in other columns on the same row then it will jump to the actual first empty row. I just need that cell.

A B C
NOW() value
THIS IS WHERE I NEED NOW TO GO value
function copy() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var svA=ss.getRange('A2').getValue();
  var tsh=ss.getSheetByName('SheetName');
  tsh.getRange(tsh.getLastRow()+1,2).setValue(svA);
  }`

I have tried the above table and it skipped B2 and went to B3 because I have data in C2.

Upvotes: 0

Views: 61

Answers (1)

TheWizEd
TheWizEd

Reputation: 8596

Replace

tsh.getRange(tsh.getLastRow()+1,2).setValue(svA);

With

let last = tsh.getRange("B1").getDataRegion(SpreadsheetApp.Dimension.ROWS);
tsh.getRange(last.getNumRows()+1,2).setValue(svA)

Upvotes: 0

Related Questions