|
|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下。。。
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
tm = Timer
Dim wb As Workbook, sht As Worksheet, sh As Worksheet
arr = Me.[b3].CurrentRegion
brr = Me.[i3].CurrentRegion
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
For j = 1 To UBound(arr, 2)
s = arr(i, j)
If s <> Empty Then d(s) = d(s) + 1
Next
Next
Set dic = CreateObject("scripting.dictionary")
For i = 2 To UBound(brr)
For j = 1 To UBound(brr, 2)
s = brr(i, j)
If s <> Empty Then dic(s) = dic(s) + 1
Next
Next
Me.[s3].Resize(1000, 4).ClearContents
Me.[s3].Resize(d.Count, 2) = Application.Transpose(Array(d.keys, d.items))
Set Rng = Me.[s3].Resize(d.Count, 2)
Me.Sort.SortFields.Clear
Me.Sort.SortFields.Add2 Key:=Rng.Cells(1, 2), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With Me.Sort
.SetRange Rng
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Me.[u3].Resize(dic.Count, 2) = Application.Transpose(Array(dic.keys, dic.items))
Set Rng = Me.[u3].Resize(dic.Count, 2)
Me.Sort.SortFields.Clear
Me.Sort.SortFields.Add2 Key:=Rng.Cells(1, 2), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With Me.Sort
.SetRange Rng
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "共耗时:" & Format(Timer - tm, "0.0000") & " 秒!!!", 64
End Sub
|
评分
-
3
查看全部评分
-
|