Home > other >  How to iterate over a range and an array of data and set the iterated array values until there'
How to iterate over a range and an array of data and set the iterated array values until there'

Time:02-11

This may seem simple to you, but well....here I am.

The code below sets apparently the last value Mangas to all cells in the rangeList , while it should set Alca to A10, Mangas to F10 and stop, because there are only 2 elements.

const rngs = ["A10", "F10", "J10", "A12", "F12", "J12"];
const rangeList = sheetVendSobEnc.getRangeList(rngs).getRanges();
let coresPartes = ["Alca", "Mangas"]
  for (let a = 0; a < rangeList.length; a  ) {
    for (let n = 0; n < coresPartes.length; n  ) {
      rangeList[a].setValue(coresPartes[n])
    }
  }

Thank you in advance!

CodePudding user response:

I think what you want is this?

const rngs = ["A10", "F10", "J10", "A12", "F12", "J12"];
const rangeList = sheetVendSobEnc.getRangeList(rngs).getRanges();
let coresPartes = ["Alca", "Mangas"]
  for (let a = 0; a < rangeList.length; a  ) {
    if( coresPartes[a] ===  undefined ) return;  // or break i'm no sure
    rangeList[a].setValue(coresPartes[a])
  }
}
  • Related