|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("数据1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:d" & r)
- n = 2
- For i = 1 To UBound(arr)
- yf = Month(arr(i, 3))
- If Not d1.exists(yf) Then
- n = n + 1
- d1(yf) = n
- End If
- Next
- For i = 1 To UBound(arr)
- xm = arr(i, 1) & "+" & arr(i, 2)
- If Not d.exists(xm) Then
- ReDim brr(1 To 2, 1 To 2 + d1.Count)
- brr(1, 1) = arr(i, 1)
- brr(1, 2) = arr(i, 2)
- Else
- brr = d(xm)
- End If
- yf = Month(arr(i, 3))
- n = d1(yf)
- brr(1, n) = brr(1, n) + arr(i, 4)
- If IsEmpty(brr(2, n)) Then
- brr(2, n) = arr(i, 3) & Space(2) & arr(i, 4)
- Else
- brr(2, n) = brr(2, n) & vbLf & arr(i, 3) & Space(2) & arr(i, 4)
- End If
- d(xm) = brr
- Next
- End With
- With Worksheets("汇总")
- .Cells.Clear
- .Range("a1:b1") = Array("品番", "名称")
- .Range("c1").Resize(1, d1.Count) = d1.keys
- m = 1
- For Each aa In d.keys
- m = m + 1
- brr = d(aa)
- .Cells(m, 1).Resize(1, UBound(brr, 2)) = Application.Index(brr, 1, 0)
- For j = 3 To UBound(brr, 2)
- If Not IsEmpty(brr(2, j)) Then
- .Cells(m, j).AddComment
- .Cells(m, j).Comment.Text Text:=brr(2, j)
- End If
- Next
- Next
- End With
- End Sub
复制代码 |
|