|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr()
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("系统导出表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:i" & r)
- End With
- For i = 1 To UBound(arr)
- Select Case arr(i, 9)
- Case "水分", "灰分", "脂肪", "蛋白质"
- xm = arr(i, 9)
- Case Else
- xm = "其他剩余未项目"
- End Select
- If Not d.exists(xm) Then
- m = 1
- ReDim Preserve brr(1 To 4, 1 To m)
- Else
- brr = d(xm)
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 4, 1 To m)
- End If
- brr(1, m) = arr(i, 3)
- brr(2, m) = arr(i, 2)
- brr(3, m) = arr(i, 1)
- brr(4, m) = arr(i, 6)
- 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
- On Error Resume Next
- Set ws = Worksheets(aa)
- If Err = 0 Then
- With ws
- .Range("a5:h" & .Rows.Count).ClearContents
- .Range("a5").Resize(UBound(crr), UBound(crr, 2)) = crr
- End With
- End If
- Next
-
-
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|