让我们说
在 A1 范围内
8cm 书 + 13cm 尺子 + 0.34cm 纸 那么我如何在单元格内总结 8 + 13 + 0.34 然后 = 21.34cm
然后把总结放在A2
——————-更新问题—————————
对不起,我必须把问题说清楚!8cm书+13cm尺+尺版#2+0.34cm纸
我想知道它是否仍然适用于所有大师的代码?
这个问题困扰了我 1 周。希望能得到答案!谢谢!!
试试这个简单的基于正则表达式的 UDF。
Option Explicit
Function sumNums(str As String) As Double
Dim n As Long
Static rgx As Object, cmat As Object
If rgx Is Nothing Then
Set rgx = CreateObject("VBScript.RegExp")
End If
With rgx
.Global = True
.MultiLine = True
.Pattern = "(\-?\d*\.?\d+)"
If .test(str) Then
Set cmat = .Execute(str)
For n = 0 To cmat.Count - 1
sumNums = sumNums + CDbl(cmat.Item(n))
Next n
End If
End With
End Function
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句