简体   繁体   English

Excel VBA-将范围从一个工作表粘贴复制到工作簿中的某些工作表之后的所有工作表

[英]Excel VBA - Copy range from one sheet paste to all sheets after certain sheet in workbook

I feel like this is too simple to be stuck on, but I have a workbook with about 100 sheets, and I need to copy a range from one sheet (Sheet2 Range a1:H200) to Sheet5 AF1:AM200 and every sheet after (Sheet5 through Sheet100 or more). 我觉得这太简单了,无法粘贴,但是我的工作簿大约有100张纸,因此我需要将一个纸页(Sheet2范围a1:H200)复制到Sheet5 AF1:AM200以及(Sheet5)之后的每一页通过Sheet100或更多)。 I have tried creating a loop and copying the original range and pasting to each sheet, but it hasn't worked. 我尝试创建一个循环,然后将原始范围复制并粘贴到每张纸上,但是没有用。 I feel like this is the closest I've gotten 我觉得这是我最近得到的

Sub CopyPasteLoop()

Dim wsVar As Worksheet

For Each wsVar In ThisWorkbook.Sheets
   With wsVar
      ThisWorkbook.Worksheets("Sheet2").Range("A1:H200").Value = ThisWorkbook.Worksheets("Sheet5").Range("AF1").Value
   End With
Next wsVar

End Sub

I feel like it should be simpler, but I can't make it work. 我觉得它应该更简单,但是我无法使其工作。 Thanks! 谢谢!

Almost there. 快好了。 Try this: 尝试这个:

Sub CopyPasteLoop()

Dim wsVar As Worksheet

Dim i as Integer
For i = 5 to ThisWorkbook.Worksheets.Count
    ThisWorkbook.Worksheets(i).Range("AF1:AM200").Value = ThisWorkbook.Worksheets("Sheet2").Range("A1:H200").Value
Next i

End Sub

Or for better performance, use this: 为了获得更好的性能,请使用以下命令:

Dim vRange as Variant
vRange = ThisWorkbook.Worksheets(2).range("A1:H200")

Dim i as Integer
For i = 5 to ThisWorkbook.Worksheets.Count
    ThisWorkbook.Worksheets(i).Range("AF1:AM200").Value = vRange
Next i

Hopefully @Scott Holtzman's answer will work for you (providing your sheets are indexed in the same order as they're named). 希望@Scott Holtzman的答案对您有用(假设工作表的索引顺序与命名顺序相同)。 This approach will also work. 这种方法也将起作用。

Dim wb As Workbook, ws As Worksheet
Dim rng As Range

Set wb = ThisWorkbook
Set rng = wb.Sheets("Sheet2").Range("A1:H200")

For Each ws In wb.Sheets

    If CInt(Right(ws.Name, Len(ws.Name) - Len("Sheet"))) >= 5 Then

        ws.Range("AF1:AM200").Value = rng.Value

    End If

Next ws

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel VBA-复制/粘贴范围从一张纸到所有后续纸 - Excel VBA - Copy/Paste range from one sheet to all proceeding sheets 试图将特定范围从工作簿中的许多工作表复制到另一个工作簿中的一个工作表 vba excel? - Trying to copy specific range from many sheets in workbook to one sheet in another workbook vba excel? Excel VBA将内容从一个工作表复制到另一个工作簿工作表 - Excel VBA copy content from one Sheet into other Workbook sheet VBA将工作簿中所有工作表中选定范围内的已填充单元格复制到一个摘要工作表 - VBA Copy filled cells in selected range in all sheets within the workbook to one summary sheet 从所有工作表复制并粘贴固定行数,然后粘贴到VBA中的一张工作表中 - Copy and paste fix number of rows from all the sheets and paste into one sheet in VBA 将多张纸(但不是全部纸)的值复制/粘贴到一张纸中 - Copy/paste values from multiple sheets, but not all sheets, into one sheet VBA Excel-打开并从多个工作簿复制到一个摘要表(粘贴在顺序原始文件上) - VBA Excel - open and copy from several workbook to one summary sheet (paste on sequential raw) Excel VBA复制/粘贴列从多个工作表到不同列中的一个工作表 - Excel VBA copy/paste column from multiple sheets to one sheet in different Columns VBA - 根据汇总 Excel 表格上的条件,将工作簿中的不同模板工作表复制到另一个工作簿的多张工作表中 - VBA - copy different template sheets from a workbook, into multiple sheets of another workbook based on criteria on a summary excel sheet Excel VBA在工作表中查找文本,复制范围,粘贴到其他工作表 - Excel vba find text in sheet, copy range, paste to other sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM