|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:c" & r)
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
If IsDate(ar(i, 1)) Then
If Trim(ar(i, 2)) = "大米" Or Trim(ar(i, 2)) = "小米" Then
zd = Trim(ar(i, 2))
t = d(zd)
If t = "" Then
k = k + 1
d(zd) = k
t = k
br(k, 1) = 1
br(k, 2) = ar(i, 2)
End If
br(t, 3) = br(t, 3) + ar(i, 3)
Else
zc = Application.WeekNum((ar(i, 1)), 2)
zd = zc & "|" & Trim(ar(i, 2))
t = d(zd)
If t = "" Then
k = k + 1
d(zd) = k
t = k
br(k, 1) = zc
br(k, 2) = ar(i, 2)
End If
br(t, 3) = br(t, 3) + ar(i, 3)
End If
End If
End If
Next i
.[f1].CurrentRegion.Offset(1) = Empty
.[f2].Resize(k, UBound(br, 2)) = br
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|