excel中使用正则表达式
在表格中,经常会给出一些板件的规格,然后要我们算面积,在excel中能不能用正则表达式直接算出面积,并且输出数据到后面表格。如图,在F行上有规格,我想在H行上输出最终面积...
在表格中,经常会给出一些板件的规格,然后要我们算面积,在excel中能不能用正则表达式直接算出面积,并且输出数据到后面表格。如图,在F行上有规格,我想在H行上输出最终面积,要如何算。求大佬帮忙。
展开
2个回答
展开全部
Function JiSuan(Rng As Range) As Single
Dim Reg As New RegExp
Dim R As String
On Error GoTo ErrHand
R = (Rng)
Reg.Global = True
Reg.Pattern = "[\u4e00-\u9fa5]|m|M"
R = Reg.Replace(R, "")
Reg.Pattern = "×"
R = Reg.Replace(R, "*")
RegSZCC R
RegSZJJ R
JiSuan = Round(CSng(R), 4)
Set Reg = Nothing
Exit Function
ErrHand:
JiSuan = Err.Description
End Function
Sub RegSZCC(ByRef S As String)
Dim Reg As New RegExp
Dim MS
Dim R As String
Reg.Pattern = "(\d+\.{0,1}\d*)(\*|\\)(\d+\.{0,1}\d*)"
Set MS = Reg.Execute(S)
If MS.Count = 1 Then
If MS(0).SubMatches(1) = "\" Then
R = Format(CSng(MS(0).SubMatches(0)) / CSng(MS(0).SubMatches(2)), "0.00000")
Else
R = Format(CSng(MS(0).SubMatches(0)) * CSng(MS(0).SubMatches(2)), "0.00000")
End If
S = Reg.Replace(S, R)
RegSZCC S
End If
End Sub
Sub RegSZJJ(ByRef S As String)
Dim Reg As New RegExp
Dim MS
Dim R As String
Reg.Pattern = "(\d+\.{0,1}\d*)(\+|\-)(\d+\.{0,1}\d*)"
Set MS = Reg.Execute(S)
If MS.Count = 1 Then
If MS(0).SubMatches(1) = "+" Then
R = Format(CSng(MS(0).SubMatches(0)) + CSng(MS(0).SubMatches(2)), "0.00000")
Else
R = Format(CSng(MS(0).SubMatches(0)) - CSng(MS(0).SubMatches(2)), "0.00000")
End If
S = Reg.Replace(S, R)
RegSZJJ S
End If
End Sub
EXCEL中调用方法
B1=jisuan(A1)
TableDI
2024-07-18 广告
2024-07-18 广告
仅需3步!不写公式自动完成Excel vlookup表格匹配!Excel在线免,vlookup工具,点击16步自动完成表格匹配,无需手写公式,免费使用!...
点击进入详情页
本回答由TableDI提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询