我已经能够制作工作表的精确副本并将其添加到工作簿中:
Sub Test()
Dim ws1 As Worksheet
Set ws1 = ThisWorkbook.Worksheets("Detailed List")
ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
End Sub
但是我试图将复制的工作表粘贴到另一个工作表上。例如,我正在尝试复制工作表"详细列表"并将其粘贴并覆盖"测试表",但我能够处理上述代码的是另一个工作表。任何帮助都会很棒。
答案 0 :(得分:2)
你几乎拥有它,并且你自己的解决方案有效......然而,在完成的努力中......
Sub Test()
Dim ws1 As Worksheet
Dim ws1Copy As Worksheet
Set ws1 = ThisWorkbook.Worksheets("Detailed List")
ws1.Copy ThisWorkbook.Sheets(Sheets.Count) 'we can't set the copied object directly to a varaiable, but it becomes the active sheet by default
Set ws1Copy = ActiveSheet 'assign the newly copied activesheet to a variable
Application.DisplayAlerts = False 'supress warnings, the delete method gives the user a warning
Sheets("Testing Sheet").Delete 'delete the testing sheet
Application.DisplayAlerts = True 'un-supress the warnings
ws1Copy.Name = "Testing Sheet" 'change the name of the copied sheet to the testing sheet.
End Sub
答案 1 :(得分:1)
所以我最终这样做了:
Worksheets("Detailed List").Range("A7").CurrentRegion.Copy
Worksheets("Detailed Copy").Range("A7").PasteSpecial
我在开始运行宏之前首先复制了详细列表。然后我突出显示了所有数据点和标题,并覆盖了复制。我需要这样做因为我正在创建一个宏,每当有人更改"详细列表"中的单元格时,我需要显示以前在单元格中的旧值,因此基本上有两个副本对于List,我可以先进行比较,然后只是反复复制列表,这样它就会自动更新为已经发生的任何更改。