我很擅长excel并且遇到了这个问题。我正在尝试复制模板表并制作动态数量的背靠背副本。我想让每个表的标题成为客户的名称,我将从另一个表中提取。这就是我的意思:
任何帮助都将受到高度赞赏。我希望我的解释有意义,但如果我需要澄清我的意思,请告诉我。
答案 0 :(得分:1)
如果您要将客户列表放在H列上,那么这会将表格复制到Sheet2中:
Sub foo()
LastRow = Sheet1.Cells(Sheet1.Rows.Count, "H").End(xlUp).Row ' Count Column H as that's where the customer list is
For i = 2 To LastRow 'loop from row 2 to the last on column H
NewCustomer = Sheet1.Cells(i, 8).Value 'get the customer Name 8 being Column H
LastRow2 = Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Row + 1 'find the next free row in Sheet2
Sheet1.Range("A1:C4").Copy Destination:=Sheet2.Range("A" & LastRow2) 'paste the range into Sheet2
Sheet2.Range("A" & LastRow2).Value = NewCustomer 'Replace the Customer Name
Next i
End Sub