|
楼主 |
发表于 2024-6-23 17:21
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub t()
arr = ThisWorkbook.Sheets("sheet1").Range("B2").Resize(Thisorkbook.Sheets("sheeti").Cells(Rows.Count, 2).End(xlUp).Row - 1, 1).Value
Dim brr As Variant: ReDim brr(1 To UBound(arr, 1), 1 To 5)
For i = 1 To UBound(brr, 1)
templ = Split(arr(i, 1), "、")
temp2 = Split(temp1(1), "+")
For j = 1 To UBound(brr, 2)
brr(i, 1) = temp1(0)
temp3 = RegReplace(temp2(e), ")\d", "")
brr(i, 2) = RegReplace(temp3, "[A-Z]+", "")
brr(i, 3) = RegReplace(temp3, "[--龟]+", "")
brr(i, 4) = CInt(ExtractNumbers(temp2(0)))
brr(i, 5) = temp2(1)
Next j
Next i
brr = ArraySortTwo(brr, 1, , 2, , 3, , 4, , 5)
Dim crr As Variant: ReDim crr(1 To UBound(brr), 1 To 1) As String
For i = 1 To UBound(brr)
crr(i, 1) = brr(i, 1) & "、" & brr(i, 2) & brr(i, 3) & brr(i, 4) & "+ " & brr(i, 5)
Next i
ThisWorkbook.Sheets("sheet1").Range("c2").Resize(UBound(crr), UBound(crr, 2)) = crr
End Sub
Function ExtractNumbers(ByVal inputstring As String) As String
Dim outputstring As String, i As Long, lenstr As Long
lenstr = Len(inputstring)
For i = 1 To lenstr
If IsNumeric(Mid(inputstring, i, 1)) Then outputstring = outputstring & Mid(inputstring, i, 1)
Next i
ExtractNumbers = outputstring
End Function
Function RegReplace(s, pstrt, rstr) '正则替换
Static regex As Object
Dim temp
If regex Is Nothing Then Set regex = CreateObject("vBScript.RegExp")
With regex
.Global = True
.Pattern = pstrt
temp = .Replace(s, rstr)
End With
RegReplace = temp
End Function
运行不了~~我是2021版本的office |
|