嗨,我正在寻找创建代码以在所有工作表中复制某些列(从AH到AX),然后跳过名为“汇总”和“归类结果”的工作表
我已经有这个
Sub FillSheets()
Dim ws As Worksheets
Dim worksheetsToSkip As Variant
Dim rng As Range
Dim sh As Sheet1
Set rng = sh.Range("AH1:AX7200")
worksheetsToSkip = Array("Aggregated", "Collated Results")
For Each ws In Worksheets
If IsError(Application.Match(ws.Name, worksheetsToSkip, 0)) Then
End Sub
答案 0 :(得分:0)
这将
AH1 - AX1
复制到Column AH
确定的最后使用的行(如果需要,请更新列)Sheet1
的工作表上“粘贴”数据(如果需要,请更新)。数据将粘贴在Column AH
的第一个可用空白行上。尚不清楚要将数据粘贴到哪一列。您只需将AH
更改为Some Column
即可修改“复制”和“粘贴”用引号引起来,因为我们在这里实际上只是在传递值,因为这样做更快。实际上,我们将两个相等大小范围的值设置为彼此相等。
Option Explicit
Sub AH_AX()
'Update "Sheet1" to sheet where data is being pasted
Dim ms As Worksheet: Set ms = ThisWorkbook.Sheets("Sheet1")
Dim ws As Worksheet, wsLR As Long, msLR As Long
Dim CopyRange As Range, PasteRange As Range
For Each ws In Worksheets
If ws.Name <> "Aggregated" And ws.Name <> "Collated Results" Then
'Determine last rows
wsLR = ws.Range("AH" & ws.Rows.Count).End(xlUp).Row
msLR = ms.Range("AH" & ms.Rows.Count).End(xlUp).Offset(1).Row
'Set Ranges
Set CopyRange = ws.Range("AH1:AX" & LR)
Set PasteRange = ms.Range("AH" & msLR).Resize(CopyRange.Rows.Count, CopyRange.Columns.Count)
'Value Transfer (Quicker than copy/paste)
PasteRange.Value = CopyRange.Value
End If
Next ws
End Sub