manc stu
manc stu

Reputation: 15

insertRowBefore() not displaying values

Can someone advise what I am doing wrong with the following code please? I know it's simple but I think I've been staring at the screen for too long!

function addDelivery() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var srcSheet = ss.getSheetByName("Sheet7");

  var range = srcSheet.getRange("B3:J3").getValues();
  srcSheet.insertRowBefore(6);
  srcSheet.getRange(6,2,1,4).setValues([['B3', 'C3', 'D3', 'E3' , 'F3' , 'G3' , 'H3' , 'I3' , 'J3']]);

I'm obviously trying to append the values in cells B3:J3, not have it show B3, C3, D3 etc in the appended row!

Upvotes: 0

Views: 455

Answers (2)

manc stu
manc stu

Reputation: 15

Sorry for the post. The answer was obvious....

srcSheet.getRange(6,2,1,9).setValues(range);

Was as simple as that!

Hope this helps someone.

Best regards manc

Upvotes: 0

Cooper
Cooper

Reputation: 64110

Using getRange() and setValues() together

function addDelivery() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var srcSheet = ss.getSheetByName("Sheet7");
  srcSheet.insertRowBefore(6);

First Parameter is row 3

Second Parameter is column B or 2

Third Parameter is number of rows which is 1

Fourth Parameter is number of columns which 9

  srcSheet.getRange(3,2,1,9).setValues([['B3', 'C3', 'D3', 'E3' , 'F3' , 'G3' , 'H3' , 'I3' , 'J3']]);

You could have also done it this way to keep from having to count

var data=[['B3', 'C3', 'D3', 'E3' , 'F3' , 'G3' , 'H3' , 'I3' , 'J3']];
srcSheet.getRange(3,2,data.length,data[0].length).setValues(data);

Sheet.getRange()

Range.setValues()

Upvotes: 3

Related Questions