将Excel电子表格中的行复制到新电子表格中L列中值的数量

我有一个Excel电子表格,提供有关抽奖的信息。

每行都有一个人买票的信息。

问题是,我需要制作一个新的电子表格(最终,我需要把它合并成标签),每张票一行,但是如果一个人买了2张票,他们的信息只在原始电子表格的一行中,与“L”列中的票数量相关联。

所以我需要一个macros来看看他在L列中的值,并将该行复制到一个新的电子表格L次 – 如果他们买了一张票,而L列中的值是1,则它将复制一次,如果他们买了3张票,而L栏中的值是3,那么它会复制3次。

有人能告诉我如何去做这个?

如果在邮件合并过程中有办法做到这一点,这应该是工作2,我只是想到,先制作一个新的电子表格,然后只是从新的工作表制作标签。

谢谢!!

我最终在网站上find了一些代码,并根据我的需要进行了修改。 这就是我正在使用的:

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