|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 统计()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim cr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With ActiveSheet
r = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("b2:c" & r)
rs = .Cells(Rows.Count, 6).End(xlUp).Row
br = .Range("e2:g" & rs)
ReDim cr(1 To 1000, 1 To 2)
For i = 3 To UBound(br)
If Trim(br(i, 1)) = "" Then
br(i, 1) = br(i - 1, 1)
End If
Next i
For i = 4 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
If InStr(ar(i, 1), "礼盒") = 0 Then
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
cr(k, 1) = ar(i, 1)
End If
cr(t, 2) = cr(t, 2) + ar(i, 2)
Else
zd = Trim(ar(i, 1))
For s = 3 To UBound(br)
If Trim(br(s, 1)) = zd Then
t = d(Trim(br(s, 2)))
If t = "" Then
k = k + 1
d(Trim(br(s, 2))) = k
t = k
cr(k, 1) = br(s, 2)
End If
cr(t, 2) = cr(t, 2) + ar(i, 2) * br(s, 3)
End If
Next s
End If
End If
Next i
ws = .Cells(Rows.Count, 9).End(xlUp).Row
If ws > 3 Then .Range("i3:jj" & ws) = Empty
.[i3].Resize(k, 2) = cr
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|