|
本帖最后由 ykcbf1100 于 2024-2-15 10:41 编辑
代码供参考。。。- Sub ykcbf() '//2024.2.15
- Set d = CreateObject("Scripting.Dictionary")
- Set reg = CreateObject("VBScript.RegExp")
- r = Me.Cells(Rows.Count, 1).End(3).Row
- arr = Me.Range("a1:b" & r)
- ReDim brr(1 To 1000, 1 To 20)
- With reg
- .Global = True
- .Pattern = "([a-zA-Z]+\d+)|(\d+)|([\u4e00-\u9fa5]+)"
- End With
- n = 2
- For i = 2 To UBound(arr)
- st = arr(i, 1)
- Set mh = reg.Execute(st)
- s1 = mh(0).Value & "|" & mh(1).Value
- If Not d.exists(s1) Then
- m = m + 1
- d(s1) = m
- brr(m, 1) = mh(0).Value
- brr(m, 2) = mh(1).Value
- End If
- s2 = mh(2).Value
- If Not d.exists(s2) Then
- n = n + 1
- d(s2) = n
- End If
- r = d(s1): c = d(s2)
- brr(r, c) = arr(i, 2)
- Next
- With Sheets("Sheet2")
- .UsedRange.Offset(2).Clear
- .Columns(1).NumberFormatLocal = "@"
- .[a3].Resize(m, n) = brr
- .[a3].Resize(m, n).Borders.LineStyle = 1
- End With
- Set d = Nothing
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|