|
代码如下。。。
Sub test()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set dict = CreateObject("scripting.dictionary")
Set d = CreateObject("scripting.dictionary")
arr = Sheet1.[h1].CurrentRegion
For i = 2 To UBound(arr)
s = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3)
dict(s) = ""
d(arr(i, 1)) = ""
Next
i = 0
With Sheet1
.Cells(32, "l").CurrentRegion.Clear
For Each k In dict.keys
i = i + 1
s = Split(k, "|")
.Cells(32 + i, "l").Resize(, 3) = s
Next
ssss = Application.Rept(d.keys, 1)
ssss = Join(ssss, ",")
.Sort.SortFields.Clear
x = .Cells(Rows.Count, "l").End(3).Row
.Sort.SortFields.Add2 Key:= _
.Range("l33:l" & x), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder _
:=ssss & "", DataOption:=xlSortNormal
.Sort.SortFields.Add2 Key:=.Range("m33")
With .Sort
.SetRange Sheet1.[l33].CurrentRegion
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
For j = 0 To 1
For i = x To 33 Step -1
If .Cells(i, 12 + j) = .Cells(i - 1, 12 + j) Then Range(.Cells(i, 12 + j), .Cells(i - 1, 12 + j)).Merge
Next
Next
.Cells(32, "l").Resize(, 3) = arr
.Cells(32, "l").Resize(, 3).Font.Bold = True
.Cells(32, "l").Resize(, 3).Font.Size = 12
With .Cells(32, "l").CurrentRegion
.Borders.LineStyle = 1
.HorizontalAlignment = xlCenter
End With
End With
Set dict = Nothing
Set d = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Beep
End Sub
|
|