|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("数据源")
- r = .Cells(.Rows.Count, 5).End(xlUp).Row
- arr = .Range("a4:s" & r)
- End With
- For i = 1 To UBound(arr)
- Select Case Left(arr(i, 5), 1)
- Case "T"
- lx = "铁"
- Case "X", "L", "M", "S"
- lx = "铝"
- Case Else
- lx = "五金"
- End Select
- xm = arr(i, 14) & "(" & lx & ")"
- If Not d.exists(xm) Then
- m = 1
- ReDim brr(1 To 16, 1 To m)
- Else
- brr = d(xm)
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 16, 1 To m)
- End If
- For j = 5 To 9
- brr(j - 4, m) = arr(i, j)
- Next
- brr(7, m) = arr(i, 3)
- brr(8, m) = arr(i, 19)
- brr(9, m) = arr(i, 16)
- brr(11, m) = arr(i, 14)
- brr(12, m) = arr(i, 10)
- d(xm) = brr
- Next
- For Each aa In d.keys
- brr = d(aa)
- ReDim crr(1 To UBound(brr, 2), 1 To UBound(brr))
- For i = 1 To UBound(brr)
- For j = 1 To UBound(brr, 2)
- crr(j, i) = brr(i, j)
- Next
- Next
- For i = 1 To UBound(crr)
- crr(i, 15) = crr(i, 6) * crr(i, 12)
- Next
- On Error Resume Next
- Worksheets(aa).Delete
- On Error GoTo 0
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- With ws
- .Name = aa
- .Range("a3:p3") = Array("产品编码", "产品名称", "规格", "效果", "单位", "单价", "订单号码", "送货日期", "送货单号", "再编号", "收货单位", "数量", "折为对", "公斤(KG)", "金额", "备注")
- .Range("a4").Resize(UBound(crr), UBound(crr, 2)).Value = crr
- With .Range("a3").Resize(1 + UBound(crr), UBound(crr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 10
- End With
- End With
- End With
- Next
-
- ' With .UsedRange
- ' .HorizontalAlignment = xlCenter
- ' .VerticalAlignment = xlCenter
- ' End With
- End Sub
复制代码 |
|