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

Extract multiple numbers within parentheses in a text string and sum them in Google Sheets

$
0
0

I have order numbers and quantities recorded like this: # 5397 (5) # 5387 (15) which means 5 and 15, in total 20. The expected result is 20.

I already have a custom function implemented in Microsoft Excel VBA:

Function SUMAPA(n1 As String)Longitud = Len(n1)For i = 1 To LongitudIf Mid(n1, i, 1) = "(" ThenIf Mid(n1, i + 2, 1) = ")" ThenValor = Val(Mid(n1, i + 1, 1))SUMAPA = SUMAPA + Val(Mid(n1, i + 1, 1))ElseIf Mid(n1, i + 3, 1) = ")" ThenValor = Val(Mid(n1, i + 1, 2))SUMAPA = SUMAPA + Val(Mid(n1, i + 1, 2))ElseIf Mid(n1, i + 4, 1) = ")" ThenValor = Val(Mid(n1, i + 1, 3))SUMAPA = SUMAPA + Val(Mid(n1, i + 1, 3))ElseIf Mid(n1, i + 5, 1) = ")" ThenValor = Val(Mid(n1, i + 1, 4))SUMAPA = SUMAPA + Val(Mid(n1, i + 1, 4))ElseIf Mid(n1, i + 6, 1) = ")" ThenValor = Val(Mid(n1, i + 1, 5))SUMAPA = SUMAPA + Val(Mid(n1, i + 1, 5))ElseIf Mid(n1, i + 7, 1) = ")" ThenValor = Val(Mid(n1, i + 1, 6))SUMAPA = SUMAPA + Val(Mid(n1, i + 1, 6))End IfEnd IfNext iDebug.Print ValorDebug.Print SUMAPAEnd Function

It works well in Excel:

Excel function

I want to do the same thing in Google Sheets.


Viewing all articles
Browse latest Browse all 9782

Trending Articles



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