VBA将列复制到现有表中

时间:2017-09-22 01:57:23

标签: excel vba excel-vba

VBA noob在这里。我有Dashboard,Master和Aggregate表。我创建了一个宏,以便在按下"创建副本时#34;按钮,主表格被复制到新的"工具"基于列表命名的工作表。创建新工作表后,我希望将每个新工作表中的特定列复制到聚合中(或作为新表列插入)。当添加的纸张数量及其名称可变时,这很困难。

以下是创建新工作表的代码:

Sub CreateSheetsFromAList()
Dim MyCell As Range, MyRange As Range
Dim tbl As ListObject

Set MyRange = Sheets("Dashboard").Range("A24:A28")
Set MyRange = Range(MyRange, MyRange.End(xlDown))

For Each MyCell In MyRange
    Sheets.Add after:=Sheets(Sheets.Count) 'creates a new worksheet
    Sheets(Sheets.Count).Name = MyCell.Value ' renames the new worksheet
    Worksheets("RTM - Master").Cells.Copy ActiveSheet.Range("A1")
    ActiveSheet.ListObjects(1).Name = MyCell.Value
    ActiveSheet.Cells(1, 6).Value = MyCell.Value & " " & "Capability"
    ActiveSheet.Cells(1, 7).Value = MyCell.Value & " " & "LOE"
    ActiveSheet.Cells(1, 8).Value = MyCell.Value & " " & "Pts"
    Range("f1", Range("f1").End(xlDown)).Select
Next MyCell
End Sub

提前致谢!

0 个答案:

没有答案