|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet2")
- r = .Cells(.Rows.Count, 3).End(xlUp).Row
- arr = .Range("b3:d" & r)
- For i = 1 To UBound(arr)
- If Len(arr(i, 1)) <> 0 Then
- xm = arr(i, 1)
- End If
- If Len(arr(i, 3)) <> 0 Then
- If Not d.exists(xm) Then
- m = 1
- ReDim brr(1 To 2, 1 To m)
- Else
- brr = d(xm)
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 2, 1 To m)
- End If
- brr(1, m) = arr(i, 2)
- brr(2, m) = arr(i, 3)
- d(xm) = brr
- End If
- Next
- End With
- With Worksheets("sheet3")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("b3:f" & r)
- End With
- With Worksheets("sheet4")
- .Range("b3:i" & .Rows.Count).Clear
- m = 3
- For i = 1 To UBound(arr)
- m0 = m
- For Each aa In d.keys
- m1 = m
- brr = d(aa)
- ReDim crr(1 To UBound(brr, 2), 1 To UBound(brr))
- For x = 1 To UBound(brr)
- For y = 1 To UBound(brr, 2)
- crr(y, x) = brr(x, y)
- Next
- Next
- For x = 1 To UBound(crr)
- crr(x, 2) = arr(i, 5) - crr(x, 2)
- Next
- With .Cells(m, 7)
- .Value = aa
- .Resize(UBound(crr), 1).Merge
- End With
- .Cells(m, 8).Resize(UBound(crr), UBound(crr, 2)) = crr
- m = m + UBound(crr)
- Next
- .Cells(m0, 2).Resize(1, 5) = Application.Index(arr, i, 0)
- For j = 2 To 6
- .Cells(m0, j).Resize(m - m0, 1).Merge
- Next
- Next
- .Range("b2:i" & m - 1).Borders.LineStyle = xlContinuous
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|