1

I use now the following macro in my worksheet:

With Sheets("missing_artikels")
        .Range("A1:F" & .Cells(.Rows.Count, 1).End(xlUp).Row).Copy Sheets("Master").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End With

Instead of copy the data to the local file, i want copy the data to a external file on location I:\sales\Funnel\funnel.xls in worksheet "funnel".

How can i combine this? Thanks.

4

1 回答 1

2

这可能是一个有趣的建议,但美丽从来不在于编写复杂的代码,而是编写简单的代码,即使你在一年后看到它,你也能理解它:)

总是用简单易懂的行来分解你的代码。例如,我已将您的请求与您现有的代码结合起来。我已经声明了相关变量(参见获取 lastrow、工作表名称等

这是你正在尝试的吗?

Option Explicit

Const wbPath = "I:\sales\Funnel\funnel.xls"

Sub Sample()
    Dim wbI As Workbook, wbO As Workbook
    Dim wsI As Worksheet, wsO As Worksheet
    Dim wsILrow As Long, wsOLrow As Long

    '~~> Input Workbook
    Set wbI = ThisWorkbook
    Set wsI = wbI.Sheets("missing_artikels")

    '~~> Output Workbook
    Set wbO = Workbooks.Open(wbPath)
    Set wsO = wbO.Sheets("funnel")
    wsOLrow = wsO.Range("A" & wsO.Rows.Count).End(xlUp).Row + 1

    With wsI
        wsILrow = .Range("F" & .Rows.Count).End(xlUp).Row
        .Range("A1:F" & wsILrow).Copy wsO.Range("A" & wsOLrow)
    End With

    '
    ' '~~> Rest of the code
    '
End Sub

高温高压

于 2012-05-15T08:28:13.590 回答