Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to copy over a specific range for every sheet after a specific one, instead of just one value

I come here with a rather specific inquiry I couldn´t quite figure out on my own, since I am probably running into somewhat of a language barrier for this.

Essentially, I have this function:

function moneyowened() {
  var out = new Array()
  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  for (var i=2 ; i<sheets.length ; i++) out.push([sheets[i].getRange("a44").getValue()])
  return out 
}

Which works for it´s intended purpose perfectly, as it makes an array out of every value of every sheet after the second. Now, for another project, I thought to copy this over since it required a similar task.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The difference being: the target that needs to be copied is an actual range of values. (specifically a row)

The difficulty lies within this factor as I can not figure out how to make it actually apply to a range of values. It either returns blank fields, or just the first value.

I have naturally tried to apply "getValues" and different ways of declaring the range, however, I only ever get either a blank row or just the first value of the row I need to copy.

One way I could resolve this is naturally to simply create a function to get each value independently, but that would be extremely tedious, and so, I wanted to ask if there is an solution I am blind to.

Thanks most kindly for any aid rendered.

Lists of Variations tried:


for (var i=2 ; i<sheets.length ; i++) out.push([sheets[i].getRange("a44:z44").getValues()])

This results in a Blank row

>Solution :

Get Rows

function getRow44() {
  var out = [];
  SpreadsheetApp.getActive.getSheets().forEach((sh, i) => {
    if (i > 1) out.push(sh.getRange(44,1,1,sh.getLastColumn()).getValues().flat());
  });
  console.log(JSON.stringify(out));
  return out;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading