我一直在苦苦寻找使用VBA一次复制多张纸的方法。问题是,我需要他们保持彼此的相对参考。例如:
I have 3 sheets:
1. Print (formulas point to TV - Input)
2. Print - Input
3. Print - plan (formulas point to TV - Input)
I need to copy them so that all formulas point to their new respective sheets.
1. Print (2) (formulas point to Print - Input (2))
2. Print - Input (2)
3. Print - plan (2) (formulas point to Print - Input (2))
这可以通过Ctrl手动完成。 +将工作表拖动到新位置。但是如何在VBA中执行此操作?
修改 名称“打印”设置为运行时。所以它也可以是电视或电台。它来自一个字符串。
任何帮助表示赞赏!
答案 0 :(得分:2)
尝试这样的事情:
Sheets(Array("Print", "Print - input", "Print - plan")).Copy After:=Sheets(Sheets.Count)
使用索引引用编辑
Sheets(Array(1, 2, 3)).Copy After:=Sheets(Sheets.Count)
使用变量引用:
Dim sht1 as String, sht2 as String, sht3 As String
sht1 = "Print"
sht2 = "Print - input"
sht3 = "Print - plan"
Sheets(Array(sht1, sht2, sht3)).Copy After:=Sheets(Sheets.Count)
使用动态数组(这里有3个元素静态,但也可以是任何动态数组):
Dim arrSHT as Variant
arrSHT = array("Print", "Print - input", "Print - Plan")
Sheets(arrSHT).Copy After:=Sheets(Sheets.Count)