Sub copy2()
Dim rng As Range
Dim ar As Variant
With Sheet1
m = .Cells(2, Columns.Count).End(xlToLeft).Column
Set rng = .Rows(2).Find("机器人数量", , , , , , 1)
If rng Is Nothing Then MsgBox "找不到机器人数量字段!": End
lh = rng.Column
h = .Cells(Rows.Count, "a").End(xlUp).Row
ar = .Range(.Cells(2, 1), .Cells(h, m))
sl = Application.Sum(.Range(.Cells(3, lh), .Cells(h, lh)))
End With
Dim arr()
ReDim arr(1 To sl, 1 To UBound(ar, 2))
For i = 2 To UBound(ar, 1)
If Trim(ar(i, lh)) <> "" Then
If IsNumeric(ar(i, lh)) Then
gs = ar(i, lh)
For s = 1 To gs
n = n + 1
For j = 1 To 4
arr(n, j) = ar(i, j)
Next j
arr(n, 5) = "R" & Format(s, "00")
Next s
End If
End If
Next i
With Sheet2
.UsedRange = Empty
.[a3].Resize(n, UBound(arr, 2)) = arr
End With
MsgBox "ok!"
End Sub
|