|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 分类()
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Dim br(), cr()
ar = Sheets("仓库").[a1].CurrentRegion
ReDim br(1 To UBound(ar), 1 To 3)
ReDim cr(1 To UBound(ar), 1 To 3)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
br(k, 1) = ar(i, 1)
br(k, 2) = ar(i, 2)
End If
br(t, 3) = br(t, 3) + ar(i, 3)
End If
If Trim(ar(i, 4)) <> "" Then
tk = d(Trim(ar(i, 4)))
If tk = "" Then
kk = kk + 1
d(Trim(ar(i, 4))) = kk
tk = kk
cr(kk, 1) = ar(i, 1)
cr(kk, 2) = ar(i, 2)
End If
cr(tk, 3) = cr(tk, 3) + ar(i, 3)
End If
Next i
With Sheets("分类1")
.[a1].CurrentRegion.Offset(1) = Empty
.[a2].Resize(k, 3) = br
End With
With Sheets("分类2")
.[a1].CurrentRegion.Offset(1) = Empty
.[a2].Resize(kk, 3) = cr
End With
End Sub
|
|