Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Google sheets custom function gives an ERROR "#ERROR!" formula parse error [closed]

$
0
0

So this is my first time using scripts, (also sorry for my bad english, it's my second language), I'm using this script that sum the values from the cells that have the same background color, the custom function is sumColoredCells(sumRange,colorRef), so sumRange is the cells that will be evaluated and the colorRefis the cell that have the background color you want, in my spreadsheet I'm using: sumColoredCells(C5:C17,A20) basically whats it does is sum the values from de cells in the range C5 to C17 that have the same background color of A20. The script works because when I debug it in Apps Script, it returns the correct value wich is 600, as you can see in the second image, but inside de spreadsheet in the cell C20 where the formula is just appears #ERROR! as you can see in the first image, but there should be the number 600 like the example in the third image. So I need help to fix this, (and yes I'm on the same account on Apps Script and Google Sheets).

 function sumColoredCells(sumRange,colorRef) {      var activeRg = SpreadsheetApp.getActiveRange();      var activeSht = SpreadsheetApp.getActiveSheet();      var activeformula = activeRg.getFormula();      var countRangeAddress = activeformula.match(/\((.*)\,/).pop().trim();      var backGrounds = activeSht.getRange(countRangeAddress).getBackgrounds();      var sumValues = activeSht.getRange(countRangeAddress).getValues();       var colorRefAddress = activeformula.match(/\,(.*)\)/).pop().trim();      var BackGround = activeSht.getRange(colorRefAddress).getBackground();      var totalValue = 0;      for (var i = 0; i < backGrounds.length; i++)        for (var k = 0; k < backGrounds[i].length; k++)          if ( backGrounds[i][k] == BackGround )            if ((typeof sumValues[i][k]) == 'number')              totalValue = totalValue + (sumValues[i][k]);      return totalValue;    };

the error on the spreadsheet

the debugger showing the right result from the active formula on the spreadsheet

how it was supposed to be


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>