|
- Sub test()
- Dim r%, i%, m%
- Dim arr, brr, yrr(), zrr()
- With Worksheets("明细")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:g" & r)
- End With
- For i = 5 To UBound(arr)
- If Left(arr(i, 1), 4) = "组立编号" Then
- m = m + 1
- ReDim Preserve zrr(1 To m)
- zrr(m) = Array(i + 1, i + 1)
- Else
- If m > 0 Then
- zrr(m)(1) = i
- End If
- End If
- Next
- With Worksheets("最终要的")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- brr = .Range("a1:a" & r)
- m = 0
- For i = 1 To UBound(brr)
- If brr(i, 1) = "零件编号" Then
- .Cells(i + 1, 1).Resize(9, 7).ClearContents
- m = m + 1
- ReDim Preserve yrr(1 To m)
- yrr(m) = i + 1
- End If
- Next
- p = 0
- For k = 1 To UBound(zrr)
- zs = Application.Ceiling((zrr(k)(1) - zrr(k)(0) + 1) / 9, 1)
- ys = (zrr(k)(1) - zrr(k)(0) + 1) Mod 9
- s = 0
- For i = zrr(k)(0) To zrr(k)(1) Step 9
- s = s + 1
- If s = zs And ys <> 0 Then
- hs = ys
- Else
- hs = 9
- End If
- p = p + 1
- Worksheets("明细").Cells(i, 1).Resize(hs, 7).Copy Cells(yrr(p), 1)
- Next
- Next
- End With
-
-
-
- End Sub
复制代码 |
|