First post, not so much a problem more advice.
I have been working on a loop to add a certain amount of numbers into rows of 10 in Google Scripts. I have the below code working but can't help thinking that there is a simpler way of achieving this.
I have commented the code explaining what section does what, but essentially it takes a number from a different cell, then creates rows of consecutive numbers in groups of 10.
function orderArea1() {
for(x = 0, y = 0, z = 1; z <= releaseNoteSH.getRange(10, 4).getValue(); z++){ // Sets variables; checks the z is lower or equal to source quantity, increase z by 1
y = y + 0.099; // Add 0.099 to y. This is to stop the row reference changing too early
releaseNoteSH.getRange(Math.floor(y + 10), x + 6).setValue(z); // Set location of first number using y rounded down to the nearest integer, and set value using z
x++; // Add 1 to x
if(x >= 10){ // If/when x reaches 10 reset x to 0
x = 0;
}
}
}
If anyone can give me an idea on how to simplify this I'd be very interested to hear!
I have only been learning JavaScript for a week or so now and this website has been invaluable so thanks to everyone on here!
Aucun commentaire:
Enregistrer un commentaire