[英]Paste a range into different sheets, based on a cell value
I have an Excel document that contains 52 weekly timetables each on a separate sheet, and a 'current' timetable, which acts as a template which may change throughout the academic year. 我有一个Excel文档,每个文档在单独的工作表上包含52个每周时间表,以及一个“当前”时间表,该时间表用作模板,在整个学年中可能会发生变化。 I've created buttons in each of the 52 timetables that autofill by going into the Current template and copying/pasting the ranges I need, but it's a bit of a slog when it changes halfway through the year and you have to go through every TT from that point on and click the button. 我已经在52个时间表中的每一个中创建了按钮,方法是进入“当前”模板并复制/粘贴我需要的范围,这些按钮会自动填充,但是当它在一年中的一半发生变化时,这有点麻烦,您必须遍历所有TT从那时起,单击按钮。
What I'd like instead is a button within the template that fills all 52 TTs, beginning on a certain week (eg, 'Week32') which is selected via a data validation drop-down within the template. 相反,我想要的是模板中的一个按钮,该按钮可填充所有52个TT,从某个星期开始(例如“ Week32”),可通过模板中的数据验证下拉菜单选择该按钮。 So you would select the week you want to fill from, click the button and away it goes. 因此,您可以选择要填写的星期,然后单击按钮,然后按一下。
Most of the code is pretty basic; 大多数代码是非常基本的。 I just don't know where to start with getting the week name from the cell and translating that to getting to the specified TT and those following it. 我只是不知道从哪里开始,从该单元格获取星期名称并将其转换为指定的TT及其后续名称。 Each TT sheet is named 'Week1', 'Week2' etc so they should already be an exact match for the values in the drop-down, if that helps. 每个TT表的名称分别为“ Week1”,“ Week2”等,因此,如果有帮助,它们应该已经与下拉列表中的值完全匹配。
The autofill buttons I have already use the following code (they run this six times; Mon-Sat). 我已经使用了自动填充按钮的以下代码(它们运行了六次;周一至周六)。 Any suggestions for improvement welcome :) 任何改进的建议,欢迎:)
Sub Fillsheet10()
'
' Fillsheet10 Macro
Sheets("CurrentSheet").Select
Range("A3:A5").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Application.CutCopyMode = False
Selection.Copy
Sheets("Week10").Select
Range("C3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
[ [ ] ]
you can update one sheet usisng: 您可以使用usisng更新一张工作表:
Sub UpdSheet()
wk = Range("F10") ' in your example Week31
Sheets("CurrentSheet").Select
Range("A3:A5").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Application.CutCopyMode = False
Selection.Copy
Sheets(wk).Select
Range("C3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
......
End Sub
or you can update all sheet when the nr. 或者您可以在nr时更新所有工作表。 week is >= to the first you will to modify tips: to modify all sheets your first week will be 1 第一周是> =,您将修改提示:要修改所有工作表,您的第一周将是1
Sub UpdAllSheet()
Dim ws As Worksheet
Dim wk As Integer
Sheets("CurrentSheet").Select
Range("A3:A5").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Application.CutCopyMode = False
Selection.Copy
wk = Range("F10") ' now you do only imput 31
For Each ws In ActiveWorkbook.Worksheets
wknr = Replace(ws.Name, "Week", "")
If wknr >= wk Then
UpdSheet (ws.Name)
End If
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.