Home > database >  Apps Script returns single value for multiple times
Apps Script returns single value for multiple times

Time:03-19

I have written this code which was supposed to copy the values from the last column in "sheet 2" between rows 3 and 10 and paste them in the nearest column with no data in "sheet 1" between rows 9 and 17.

When the code runs, the "sheet 1" rows in the specified column are populated with the value that is stored in the first row in "sheet 2".

The log shows that I am getting all the data for all the rows. What am I missing here?

var ssOne = SpreadsheetApp.openByUrl("link1");
var ssTwo = SpreadsheetApp.openByUrl("link2");
var sheet1 = ssOne.getSheetByName("sheet1");
var sheet2 = ssTwo.getSheetByName("sheet2")

function getCompetitorTrafficMonthly () {

  var lastColumn = sheet2.getLastColumn();
  var rowsData = sheet2.getSheetValues(3, lastColumn, 7, -1);
  console.log("The rows data are "   rowsData)
  sheet1.getRange(9, sheet1.getLastColumn()   1, 7).setValue(rowsData)
  
}

CodePudding user response:

Nevermind, I found the solution.

The answer to this is that I had to change setValue() to setValues()

  • Related