|
Sub 分类汇总()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant, cr As Variant
Dim d As Object, dc As Object, dic As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Set dic = CreateObject("scripting.dictionary")
Dim arr()
With Sheets("客户对应")
r = .Cells(Rows.Count, 2).End(xlUp).Row
If r < 2 Then MsgBox "客户对应表为空!": End
ar = .Range("b1:d" & r)
End With
With Sheets("销售明细")
rs = .Cells(Rows.Count, 2).End(xlUp).Row
If rs < 2 Then MsgBox "销售明细为空!": End
br = .Range("a1:g" & rs)
End With
With Sheets("运输明细")
ws = .Cells(Rows.Count, 2).End(xlUp).Row
If ws < 3 Then MsgBox "运输明细为空!": End
cr = .Range("a2:h" & ws)
End With
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
d(ar(i, 1)) = i
End If
If ar(i, 3) <> "" Then
dc(ar(i, 3)) = i
End If
Next i
ReDim arr(1 To UBound(br) + UBound(cr), 1 To 7)
For i = 2 To UBound(br)
If br(i, 1) <> "" Then
If IsDate(br(i, 1)) Then
yf = Month(br(i, 1))
zd = yf & "|" & br(i, 2)
t = dic(zd)
If t = "" Then
k = k + 1
dic(zd) = k
t = k
arr(k, 1) = yf & "月"
arr(k, 2) = br(i, 2)
xh = d(br(i, 2))
If xh <> "" Then
arr(k, 3) = ar(xh, 2)
arr(k, 4) = ar(xh, 3)
End If
End If
arr(t, 5) = arr(t, 5) + br(i, 5)
arr(t, 6) = arr(t, 6) + br(i, 7)
End If
End If
Next i
For i = 2 To UBound(cr)
If cr(i, 1) <> "" Then
If IsDate(cr(i, 1)) Then
yf = Month(cr(i, 1))
h = dc(cr(i, 4))
If h <> "" Then
dw = ar(h, 1)
zd = yf & "|" & dw
t = dic(zd)
If t = "" Then
k = k + 1
dic(zd) = k
t = k
arr(k, 1) = yf & "月"
arr(k, 2) = dw
arr(k, 3) = ar(h, 2)
arr(k, 4) = cr(i, 4)
End If
arr(t, 7) = arr(t, 7) + cr(i, 8)
End If
End If
End If
Next i
With Sheets("数据汇总")
.UsedRange.Offset(3) = Empty
.[a4].Resize(k, UBound(arr, 2)) = arr
End With
Set d = Nothing
Set dc = Nothing
Set dic = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|