逐行复制

时间:2014-09-03 04:44:10

标签: excel vba excel-vba

我需要帮助将值从一个工作表复制到另一个工作表。这是我正在使用的代码,但它不起作用。

Sub UpdateLinks()
    Dim wbSource As Workbook
    Dim wbDestination As Workbook

    'open the source workbook and select the source sheet
    Set wbSource = Workbooks.Open( _
        Filename:="C:\Users\B48184\Desktop\Losses_Breakdown_by_OEE.xls")

    'Set the destition workbook variable
    Set wbDestination = Workbooks("TryVB.xlsm")

    wbSource.Sheets("Report").Range(Cells(4, 3), Cells(14, 8)).Copy
    wbDestination.Sheets("Sheet2").Range(Cells(4, 3), Cells(14, 8)).PasteSpecial (xlPasteAll)

    Application.CutCopyMode = False

    ActiveWorkbook.Save
End Sub

2 个答案:

答案 0 :(得分:1)

不合格的Cell(...是指活动工作表,它可能与指定的工作表不同,从而导致错误。改为

With wbSource.Sheets("Report")
    .Range(.Cells(4, 3), .Cells(14, 8)).Copy
End With
With wbDestination.Sheets("Sheet2")
    .Range(.Cells(4, 3), .Cells(14, 8)).PasteSpecial xlPasteAll
End With

请注意.

答案 1 :(得分:-1)

如果你这样做怎么样:

wbSource.Sheets("Report").Range(Cells(4, 3), Cells(14, 8)).Copy
wbDestination.Activate
Sheets("Sheet2").Select
Range(Cells(4, 3), Cells(14, 8)).PasteSpecial (xlPasteAll)

这应该有用。

相关问题