问题
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