|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
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, 4)
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
|
|