参与一下- Sub aa()
- Dim ar, i, ar1(1 To 1000, 1 To 20), k, m, n, d As Object, s, m1, rng
- Set d = CreateObject("scripting.dictionary")
- s = Array(1, 3, 4, 5, 8)
- With Worksheets("工艺路线 (整理版)表一")
- ar = .UsedRange
- For i = 2 To UBound(ar, 1)
- If Not d.exists(ar(i, 2)) Then
- k = k + 1
- m1 = 0
- ar1(5 * (k - 1) + 1, 1) = ar(i, 2)
- For m = 0 To UBound(s)
- ar1(m + 5 * (k - 1) + 1, 2) = ar(1, s(m))
- ar1(m + 5 * (k - 1) + 1, 3) = ar(i, s(m))
- Next
- d(ar(i, 2)) = k
- Else
- m1 = m1 + 1
- n = d(ar(i, 2))
- For m = 0 To UBound(s)
- ar1(m + 5 * (n - 1) + 1, m1 + 3) = ar(i, s(m))
- Next
- End If
- Next
- End With
- With Worksheets("模拟的结果")
- .UsedRange.UnMerge
- .UsedRange.ClearContents
- .[a1].Resize(UBound(ar1, 1), UBound(ar1, 2)) = ar1
- For rng = 1 To .UsedRange.Rows.Count Step 5
- Range(.Cells(rng, 1), .Cells(rng + 4, 1)).Merge
- Next
- End With
- End Sub
复制代码 |