在excel中alt+F11新建
Function SumDigits(str As String, Optional avg As Boolean) As Double
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "-?\d+(?:\.\d+)?"
If .Test(str) Then
Set Matches = .Execute(str)
For Each Match In Matches
SumDigits = SumDigits + Match
Next
If avg Then SumDigits = SumDigits / Matches.Count
End If
End With
End Function
然后在单元格中使用新建的vba函数。第2个参数是是否取平均数。
=SumDigits(C2,FALSE)