# Excel混合数据直接计算公式法与正则法

1、“+”加号分割，4段字符串

2、"["左方括号前面是数值，后面是字符

=SUM(--LEFT(TRIM(MID(SUBSTITUTE(A2,"+",REPT(" ",LEN(A2))),(ROW(1:4)-1)*LEN(A2)+1,LEN(A2))),FIND("[",TRIM(MID(SUBSTITUTE(A2,"+",REPT(" ",LEN(A2))),(ROW(1:4)-1)*LEN(A2)+1,LEN(A2))))-1))

(ROW(1:4)-1)*LEN(A2)+1

SUM----是求和，求什么和？

LEFT截取的长度是FIND“["的位置减去1。

Function ExAdd(Str As Range, Parttern As String, ActionID As Integer, Optional RepStr As String = "")

Dim regex As Object

Set regex = CreateObject("vbscript.regexp")

With regex

.Global = True

.IgnoreCase = True

.MultiLine = True

.Pattern = Parttern

End With

Select Case ActionID

Case 1:

ExAdd = regex.Replace(Str, RepStr)

Case 2:

Case 3:

Dim matches As Object

Set matches = regex.Execute(Str)

For Each Match In matches

'ExStr = ExStr & Match.Value 用&链接字符串

Next

End Select

End Function

• 发表于:
• 原文链接http://kuaibao.qq.com/s/20180303A0019B00?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2022-07-05

2018-07-05

2018-06-15

2022-07-05

2022-07-05

2022-07-05

2022-07-05