sapt
sapt

Reputation: 9

Why does setValue() only pastes the first cell and not the whole range?

I'm very new to learning Script editor and I am trying a simple Copy paste code when you press a button (Drawing)

I have created a drawing button to assign script to. For the following cells to copy from cells (F3:K3) to move to (F5:K5) in the same sheet, not sure what I am doing wrong it's only copying the number I have in the first cell (F3) and copying that number to all cells pasting to. Very confused, any help would be amazing!!!

Shaun

function copypaste() { 
     var sheet = SpreadsheetApp.getActiveSpreadsheet();
     SpreadsheetApp.setActiveSheet(sheet.getSheetByName('Master Template'));
     var range = sheet.getRange('F3:K3');
     var copy = range.getValues();
     sheet.getRange('F5:K5').setValue(copy)
}

Upvotes: 1

Views: 321

Answers (1)

Jescanellas
Jescanellas

Reputation: 2608

As ross said, you need to use setValues instead. We can read in the documentation:

setValue(value)

Sets the value of the range. The value can be numeric, string, boolean or date. If it begins with '=' it is interpreted as a formula.

setValues(values)

Sets a rectangular grid of values (must match dimensions of this range).

Upvotes: 1

Related Questions