0

下面的代码将所有工作表内容从源工作簿复制到目标工作簿。工作表名称完全相同。该代码以完全相同的顺序/范围(“A2:A700”,&_“D2:D700,”&_“C2:C700”)将数据从源复制到目标工作簿中。但是,我希望上述范围内的源数据进入目标工作簿上的不同范围(I3、k3 和 AC3)。任何帮助表示赞赏。

Option Explicit

    Sub seunweb()
    'this macro copies from one workbook to another

    Dim wbSource As Workbook, wbDestination As Workbook
    Dim ws As Worksheet, rng As Range
    Dim NextRow As Long, LastRow As Long

    Application.ScreenUpdating = False

        Set wbSource = Workbooks.Open("D:\test.xls")
        Set wbDestination = ThisWorkbook
    For Each ws In wbSource.Sheets

    For Each rng In ws.Range("A2:A700," & _
                                     "D2:D700," & _
                                     "C2:C700").Areas
                wbDestination.Sheets(ws.Name).Range(rng.Address).Value = rng.Value

            Next rng

        Next ws

        wbSource.Close SaveChanges:=False

        Application.ScreenUpdating = True

    End Sub
4

1 回答 1

0

而不是你的 for 循环,使用类似的东西

Set rng = ws.Range("A2:A700")
wbDestination.Sheets(ws.Name).Range("I3").Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value

Set rng = ws.Range("D2:D700")
wbDestination.Sheets(ws.Name).Range("K3").Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value

' continue this this for each source range
于 2012-07-19T11:07:36.143 回答