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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -