|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Dim kr, icount%
- Sub GetData()
- Dim ar, i%, str$
- [l3:ae65536].Clear
- ar = Cells(1, 1).CurrentRegion
- ReDim kr(1 To 10, 1 To UBound(ar, 2) * 2)
- For i = 1 To UBound(ar, 2)
- str = Join(Application.Transpose(Application.Index(ar, , i)))
- icount = icount + 2: Call NumberCount(str, icount)
- Next
- Call iSort(kr)
- [l3].Resize(10, icount) = kr
- Erase kr: icount = 0
- End Sub
- Sub NumberCount(str, icount)
- Dim i%
- With CreateObject("vbscript.regexp")
- For i = 0 To 9
- .Pattern = "" & i & ""
- .Global = True
- kr(i + 1, icount - 1) = i: kr(i + 1, icount) = .Execute(str).Count
- Next
- End With
- End Sub
- Sub iSort(kr)
- Dim i&, j&, k%, t1, t2
- For k = 2 To UBound(kr, 2) Step 2
- For i = UBound(kr) To 2 Step -1
- For j = 1 To i - 1
- If kr(j, k) < kr(j + 1, k) Then
- t1 = kr(j, k): kr(j, k) = kr(j + 1, k): kr(j + 1, k) = t1
- t2 = kr(j, k - 1): kr(j, k - 1) = kr(j + 1, k - 1): kr(j + 1, k - 1) = t2
- End If
- Next
- Next
- Next
- End Sub
复制代码 |
|