我最终在网站here上找到了一些代码,并根据我的需要修改了它。 这就是我正在使用的:
Sub MakeTickets()
Dim X As Long, Z As Long, Qty As Long, Rw As Long
Dim StartRow As Long, LastRow As Long
Dim Source As String, Destination As String
'Define the variables below
StartRow = 2 'the row to start from in the source sheet
FirstDestination = 1 'the row to start from in the destination sheet
FirstCell = "A" 'the first column in each row that you want to copy
LastCell = "O" 'the last column in each row that you want to copy
Source = "Sold" 'source sheet name
Destination = "Tickets" ' destination sheet name
QtyClmn = "L" 'column to get the quantity from
'Until here
Rw = FirstDestination
With Worksheets(Source)
LastRow = .Cells(.Rows.Count, FirstCell).End(xlUp).Row
For X = StartRow To LastRow
Qty = Cells(X, QtyClmn).Value
For Z = 1 To Qty
Rw = Rw + 1
Worksheets(Destination).Range(FirstCell & Rw & ":" & LastCell & Rw).Value = .Range(FirstCell & X & ":" & LastCell & X).Value
Next
Next
End With
End Sub