简体   繁体   English

根据单元格值将范围粘贴到不同的工作表中

[英]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.

相关问题 宏根据特定的单元格值将行粘贴范围复制到不同的工作表中 - Macro to copy-paste range in row to different sheets based on specific cell value 宏以基于单元格值复制范围和粘贴 - Macro to Copy Range and Paste Based on Cell Value 根据单元格值复制/粘贴列范围 - Copy/Paste column range based on cell value 尝试根据单元格范围的单元格值隐藏工作表到工作表范围 - Trying to hide sheets based on cell value for a range of cells to a range of sheets 基于单元格值的Excel宏复制范围粘贴偏移量 - Excel Macro Copy Range Paste offset based on cell value 有没有一种方法可以基于不同工作表中的多个单元格来更新单元格值? - Is there a way for a cell value to be updated based multiple cells all in different sheets? 根据单元格值将工作表中的工作表复制并粘贴到其他工作簿 - Copying and pasting sheets from a workbook to a different workbook based on cell value VBA根据不同工作表上范围内的值更改单元格颜色 - VBA change cell color based on value in ranges on different sheets 从另一张纸上的单元格值复制同一张纸中范围的一部分的粘贴范围 - Copy Range From One Sheet Paste Part of Range In Same Sheet Based On Cell Value On Another Sheet 如果某个范围中的单元格的值为“ x”,则将某个范围的单元格复制并粘贴到另一张工作表中 - If cell in a range has value “x” copy and paste a range of cells into a different sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM