|
Sub 包装汇总()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("sheet1")
r = .Cells(Rows.count, 5).End(xlUp).Row
ar = .Range("a1:h" & r)
End With
With Sheets("包装汇总")
.[a1].CurrentRegion.Offset(1) = Empty
y = .Cells(1, Columns.count).End(xlToLeft).Column
h = UBound(ar) + 1
br = .Range(.Cells(1, 1), .Cells(h, y))
For j = 2 To UBound(br, 2)
If Trim(br(1, j)) <> "" Then
d(Trim(br(1, j))) = j
End If
Next j
k = 1
For i = 2 To UBound(ar)
If Trim(ar(i, 5)) = "包装" Then
If Trim(ar(i, 8)) <> "" Then
If InStr(ar(i, 8), ",") = 0 Then
zd = Trim(ar(i, 8))
t = d(zd)
If t = "" Then
k = k + 1
d(zd) = k
t = k
br(k, 1) = zd
End If
lh = d(Trim(ar(i, 4)))
If lh <> "" Then
br(t, lh) = br(t, lh) + 1
End If
Else
rr = Split(ar(i, 8), ",")
For s = 0 To UBound(rr)
If Trim(rr(s)) <> "" Then
zd = rr(s)
t = d(zd)
If t = "" Then
k = k + 1
d(zd) = k
t = k
br(k, 1) = zd
End If
lh = d(Trim(ar(i, 4)))
If lh <> "" Then
br(t, lh) = br(t, lh) + 1
End If
End If
Next s
End If
End If
End If
Next i
If k = 1 Then MsgBox "没有需要汇总的数据": End
.[a1].Resize(k, UBound(br, 2)) = br
.[a1].Resize(k, UBound(br, 2)).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|