|
Sub 数据整理()
Dim Reg1 As Object, i%, j%, Reg2 As Object, arr
Set Reg1 = CreateObject("VBScript.regexp")
Set Reg2 = CreateObject("VBScript.regexp")
Reg1.Pattern = "\d+×" '规则
Reg1.Global = True '搜索全部
Reg2.Global = True '搜索全部
For i = 2 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
arr = Split(Sheet1.Cells(i, 1), "/")
Reg2.Pattern = "-\d+"
For j = 1 To UBound(arr)
Set a = Reg1.Execute(arr(j - 1)) '返回每一个符合条件的开始位置,长度和值
Set b = Reg2.Execute(arr(j - 1))
If Reg2.test(arr(j - 1)) Then
c = Val(Split(a(0), "×")(0))
d = Val(Split(b(0), "-")(1))
x = c * d
Y = Y & Reg1.Replace(arr(j - 1), x & "×") & "/"
Else
Y = Y & arr(j - 1) & "/"
End If
Next
Reg2.Pattern = "-\d+/"
Sheet1.Cells(i, "B") = Reg2.Replace(Y, "/")
Y = ""
Next
End Sub
|
|