|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub chonggou()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim i, j, k, kk, m, n, t, irow
t = Timer
Dim ar, br
Dim d1, d2 As Object
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
irow = Sheets("总单").[f65336].End(xlUp).Row
ar = Sheets("总单").Range("f1:g" & irow)
For i = 2 To irow
d1(ar(i, 1)) = d1(ar(i, 1)) + ar(i, 2)
d2(ar(i, 1)) = d2(ar(i, 1)) + 1
Next
ReDim br(1 To 1000, 1 To 3)
For Each kk In d1.keys
For i = 2 To irow
If kk = ar(i, 1) Then
j = j + 1
For k = 1 To 2
br(j, k) = ar(i, k)
Next
br(j, 3) = d1(kk)
End If
Next
Next
With Sheets("总单")
.[a2].Resize(1000, 3).ClearContents
.[a2].Resize(1000, 3).ClearFormats
.[a2].Resize(irow - 1, 3) = br
.Range("a1:c" & irow).Sort Key1:=Columns("a"), order1:=xlDescending, Header:=xlYes
For m = 2 To irow
n = d2(.Cells(m, 1).Value)
If n > 1 Then
.Cells(m, 1).Resize(n, 1).Merge
.Cells(m, 3).Resize(n, 1).Merge
End If
Next
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "ok"
End Sub
|
|