sum comma delimited string of integers

好久不见. 提交于 2020-07-10 10:59:05

问题


In Google Sheets - I need to sum a set of numbers, where the initial cell contains delimiters and non numerics:

3; 6; 1; 3; None; 1; 1

I first replace all spaces and non numerics:

=REGEXREPLACE(AG24,"\D+",",")

Which gives: 3,6,1,3,1,1

Since =SUM(3,6,1,3,1,1) correctly provides 15, I figured I'd try passing in the REGEXREPLACE result into SUM() and magically have it compute, but doing so yields 0:

=SUM(REGEXREPLACE(AG24,"\D+",",")) = 0

I kind of expected that...

I've also tried SUMPRODUCT, which also yields 0:

=SUMPRODUCT(ARRAYFORMULA(REGEXREPLACE(AG24,"\D+",","))) = 0

Question: so how can I sum the list of string integers?


回答1:


Please try:

=sum(split(REGEXREPLACE(AG24,"\D+",","),","))



回答2:


You can try the below formula which will directly convert the string to array ad then make a sum of it.

=Sum(SPLIT(AG24,";"))

Hope it helps!




回答3:


  • =SUMPRODUCT(SPLIT(AG24, ";"))

  • =SUMPRODUCT(SPLIT(REGEXREPLACE(AG24,"\D+"," ")," "))

will work as well...



来源:https://stackoverflow.com/questions/54662379/sum-comma-delimited-string-of-integers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!