繁体   English   中英

如何在工作表之间复制一系列单元格?

[英]How do I copy a range of cells between worksheets?

我在 for 循环的最后一行出现错误。

Dim iLastCol As Integer
Dim teamsWsht As Worksheet

Set teamsWsht = ThisWorkbook.Worksheets("Teams")

iLastCol = teamsWsht.UsedRange.Columns.Count

For iCol = 2 To iLastCol

    Dim iLastRow As Integer
    Dim currWsht As Worksheet
    Dim teamsRng As Range
    Dim currRng As Range


    iLastRow = teamsWsht.Cells(Rows.Count, iCol).End(xlUp).Row              
    dTeams.Add iCol - 2, teamsWsht.Cells(5, iCol).Value                     
    Set currWsht = ThisWorkbook.Worksheets(dTeams(iCol - 2))                
    currWsht.Range("A1").Value = dTeams(iCol - 2)                           
  
    Set teamsRng = teamsWsht.Range(Cells(7, iCol), Cells(iLastRow, iCol))
    Set currRng = Range(Cells(2, 1), Cells(iLastRow - 7 + 1, iCol))
    
    currWsht.Range(currRng).Value = teamsRng.Value 'error here

Next iCol

我在最后一行收到错误 1004 方法范围的 _worksheet 失败。

在该行删除Set Set仅用于对象。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM