Creating a loop that modifies row after row in google Scripts -
rookie coder here. i'm working in google scripts project , here's i'm trying do.
essentially, trying access specific spreadsheet (called "top sheet") through aicp address has been entered in cell k2 of "2013" spreadsheet. information accessing in "top sheet" spreadsheet single number located in cell k46. then, taking value of cell k46 (located in "top sheet") , placing new cell (n2) in "2013" spreadsheet.
here's looks (and works).
function getjobactuals() { var ss = spreadsheetapp.getactivespreadsheet(); var s2 =spreadsheetapp.openbyid(ss.getsheetbyname("2013").getrange("k2:k2").getvalue()); var v2 = s2.getsheetbyname("top sheet").getrange("k46:k46").getvalue(); ss.getsheetbyname("2013").getrange("n2:n2").setvalue(v2); var s3 = spreadsheetapp.openbyid(ss.getsheetbyname("2013").getrange("k3:k3").getvalue()); var v3 = s3.getsheetbyname("top sheet").getrange("k46:k46").getvalue(); ss.getsheetbyname("2013").getrange("n3:n3").setvalue(v3);
what i'm trying now, make happen of preceding cells in "2013" spreadsheet. example, code works 1 number. cell k2 in "2013" tells retrieve value of cell k46 in "top sheet" , returns value , places new cell, n2.
how loop process happen cell range of k2 - k60 , repopulate new cell range of n2 - n60?
man hope makes sense, , appreciated. , again, above code works, trying make loop can handle more 1 thing @ time.
the answer should become clear if use sheet.getrange(row,column)
instead of sheet.getrange(a1notation)
. using row , column numbers instead of a1 notation, can apply for
loop acheive goal.
ss.getsheetbyname("2013").getrange("n3:n3").setvalue(v3); becomes ss.getsheetbyname("2013").getrange(3,14).setvalue(v3); ^^^^ row = 3, column = 14 ("n")
so can iterate on rows:
for ( row=2; row<=60; row++) { ... var s3 = spreadsheetapp.openbyid(ss.getsheetbyname("2013").getrange(row,11).getvalue()); ... ss.getsheetbyname("2013").getrange(row,14).setvalue(v3); ... }
details left you, that's basic structure loop. there more efficient ways make work, since you're new this, worry after basics working.
Comments
Post a Comment