David Howarth
David Howarth

Reputation: 33

Google Sheets - Sending Row to Another Spreadsheet

Written a Google Sheet where when a button is pressed a collated row of data is sent to a different Google Sheet. It was launched six months ago among colleagues that have full permissions to both sheets. The reason for this post was that 1 in 10 submissions goes missing and never arrives to be added to the secondary Google Sheet. Thus wondering if anyone had any ideas as to if there was an issue with my code.

sh.getRange("j7").setValue('=now()');
var range = sh.getRange('J7:R7'); //Fixed range of where the row/data is collated
var data = range.getValues();

var tss = SpreadsheetApp.openById('SHEET ID');
var ts = tss.getSheetByName('Main'); 

ts.getRange(ts.getLastRow()+1,1,1,9).setValues(data);

Many thanks for any ideas...

Upvotes: 0

Views: 53

Answers (1)

Cooper
Cooper

Reputation: 64140

Try this:

function lfunko() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Enter Your Sheet Name");
  sh.getRange("J7").setFormula('=now()');
  var range = sh.getRange('J7:R7'); 
  var data = range.getValues();
  var tss = SpreadsheetApp.openById('SHEET ID');
  var ts = tss.getSheetByName('Main');
  ts.getRange(ts.getLastRow() + 1, 1, data.length, data[0].length).setValues(data);
}

Upvotes: 1

Related Questions