Leandro Guedes
Leandro Guedes

Reputation: 111

Pass values in array to a range of cells on Google Spreadsheet

I'm tryin to read in a column of cells its numbers and backgrounng colors ,and copy it to another columuns.

I can read both and put values in arrays, so what I need is pass the values in these arrays to the range that should receive it.

That's what I'm trying, reading values in column A and pass it to column C:

var origin =["A1:A5"]
var destiny=["C1:C5"]

var ColCell = SpreadsheetApp.getActiveSpreadsheet().getRange(origin).getBackgrounds();
var ValCell=SpreadsheetApp.getActiveSheet().getRange(origin).getValues();

// now i have two arrays, ColCell and ValCell,
// that have backgound colors and Values of original
// cells in the range "A1:A5".

I can't figure how to pass values in ColCell and ValCell to ["C1:C5"]. Have anyone had this problem before?

Upvotes: 1

Views: 187

Answers (1)

Tanaike
Tanaike

Reputation: 201613

  • You want to copy the values (background colors and cell values) of "A1:A5" of the active sheet to the range of "C1:C5" of the active sheet using Google Apps Script.

If my understanding is correct, how about this modification?

Modified script:

var origin = ["A1:A5"];
var destiny = ["C1:C5"];

// Retrieve values.
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange(origin);
var ColCell = range.getBackgrounds();
var ValCell = range.getValues();

// Set values.
sheet.getRange(destiny).setBackgrounds(ColCell).setValues(ValCell);

References:

If I misunderstood your question and this was not the result you want, I apologize.

Upvotes: 1

Related Questions