VBA将某些列复制到所有工作表

时间:2018-11-27 17:05:02

标签: excel vba

嗨,我正在寻找创建代码以在所有工作表中复制某些列(从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

1 个答案:

答案 0 :(得分:0)

这将

  1. 浏览表格
  2. 将数据从AH1 - AX1复制到Column AH确定的最后使用的行(如果需要,请更新列)
  3. 在名为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