google apps script - Condensing similar and repeating code -



google apps script - Condensing similar and repeating code -

i amateur coder have searched solution , didn't come anything.

i working in google sheets , trying add together values on same row in 2 different columns together. have tried arrays couldn't first array add together first element in array b created code bellow, works ok seems far wasteful (i have 21 rows add together together).

would able @ to the lowest degree guide me right place slim down?

class="lang-js prettyprint-override">var bd1 = data.getrange("k3"); var bn1 = data.getrange("h3").getvalue(); var bo1 = data.getrange("k3").getvalue(); var bs1 = bn1+bo1; bd1.setvalue(bs1); var bd2 = data.getrange("k4"); var bn2 = data.getrange("h4").getvalue(); var bo2 = data.getrange("k4").getvalue(); var bs2 = bn2+bo2; bd2.setvalue(bs2); ...

here's 1 way go it:

var add2cells = function(labela, labelb) { var cella = data.getrange(labela); var cellb = data.getrange(labelb); cella.setvalue(cellb.getvalue() + cella.getvalue()); }; add2cells("k3", "h3"); add2cells("k4", "h4");

at point can create array of cell pairs loop through , feed add2cells function.

google-apps-script google-spreadsheet

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -