|
- Public Sub PriceList()
- Dim d As Object, p As Object, i, arr, brr, UpRow%, C%
- Set d = CreateObject("scripting.dictionary")
- Set p = CreateObject("scripting.dictionary")
- arr = Range("A1:C" & [C1].End(xlDown).Row)
- For i = 2 To UBound(arr)
- d(arr(i, 1)) = d(arr(i, 1)) + 1
- p(arr(i, 2)) = arr(i, 3)
- UpRow = [E500].End(xlUp).Row
- If d(arr(i, 1)) = 1 Then
- With Range(Cells(UpRow + 2, "E"), Cells(UpRow + 2, "F"))
- .Merge
- .Value = arr(i, 1)
- .HorizontalAlignment = xlCenter
- End With
- Cells(UpRow + 3, 5).Value = Application.WorksheetFunction.Transpose(arr(i, 2))
- Cells(UpRow + 3, 6).Value = Application.WorksheetFunction.Transpose(p(arr(i, 2)))
- Else
- Cells(UpRow + 1, 5).Value = Application.WorksheetFunction.Transpose(arr(i, 2))
- Cells(UpRow + 1, 6).Value = Application.WorksheetFunction.Transpose(p(arr(i, 2)))
- End If
- Next
- End Sub
复制代码 学习一晚上字典的一个成果,希望大神们能指点一下,我总觉得有点绕来绕去的思路不清晰
这个macro主要是将catagory的作为一个合并单元格后的表头,下面是product和price,然后空一行继续下一个catagory
|
|