Excel VBA 复制模板工作表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26332301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA copy template worksheet
提问by kireta7
I'm VBA noobs and in need to finish my assignment.
我是 VBA 菜鸟,需要完成我的作业。
I would like to copy a template worksheets into and copy some cell automatically to it.
Here's what I get from webs, and I'm stuck now..
我想将模板工作表复制到其中并自动将一些单元格复制到其中。
这是我从网上得到的,现在我被困住了..
Sub CopyTemplate()
Dim myCell As Range, MyRange As Range, Orange As Range
Set MyRange = Sheets("Isolation Section").Range("B24")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
Set Orange = Sheets("Isolation Section").Range("D24")
Set Orange = Range(MyRange, MyRange.End(xlDown))
Application.ScreenUpdating = False
For Each myCell In MyRange
Sheets("Template").Copy After:=Sheets(Sheets.Count)
With myCell
ActiveSheet.Name = .Value
ActiveSheet.Range("A13").Value = .Value
ActiveSheet.Range("E13").Value = Orange.Value
.Parent.Hyperlinks.Add Anchor:=myCell, Address:="", SubAddress:= _
"'" & .Text & "'!B24", TextToDisplay:=.Text
End With
Next myCell
Application.ScreenUpdating = True
End Sub
I have a template sheet called Template.
I create a copy of Templatesheet and name it after each row from Isolation Section(so a loop).
Then place the cell data row B24in cell
A13of the sheet.
But how about the cell data row D24from Isolation Sectioncopied to each sheets in new worksheets cell E13?
我有一个名为Template的模板表。
我创建了一个模板表的副本,并在隔离部分的每一行之后命名它(所以是一个循环)。
然后将单元格数据行B24放在工作表的单元格
A13中。
但如何对单元格数据行D24从隔离部分复制到新的工作表中各表单元格E13?
Image:
图片:
Sorry if my English is bad..
对不起,如果我的英语不好..
采纳答案by L42
Try this:
尝试这个:
For Each mycell In MyRange
Sheets("Template").Copy After:=Sheets(Sheets.Count)
With ActiveSheet
.Name = mycell
.Range("A1").Value = mycell.value
.Range("E1").Value = mycell.Offset(0, 1).Value
End With
mycell.Parent.Hyperlinks.Add Anchor:=myCell, Address:="", SubAddress:= _
"'" & mycell.Text & "'!B24", TextToDisplay:=mycell.Text
Next
回答by Sai Grr
Your description isn't very clear, but the easiest way to resolve your issue would be to just use macro recorder and copy and paste the code.
您的描述不是很清楚,但解决问题的最简单方法是使用宏记录器并复制并粘贴代码。
Here's microsoft's site on how to create/delete one: http://office.microsoft.com/en-us/excel-help/create-or-delete-a-macro-HP010342374.aspx
这是关于如何创建/删除一个的微软网站:http: //office.microsoft.com/en-us/excel-help/create-or-delete-a-macro-HP010342374.aspx
I create macros sometimes and as long as you know something about coding, you can just glue together a couple of macro recordings and have a working macro... that's actually standardised. Good luck.
我有时会创建宏,只要您对编码有所了解,您就可以将几个宏记录粘合在一起并获得一个可运行的宏……这实际上是标准化的。祝你好运。