程序正在检查错误的下一个可用行 sheet

Program is checking next available row in the wrong sheet

我编写了一个代码,可以将数据从一堆 Excel 工作簿(路径从专用 txt 文件读取)复制到主 sheet。我现在遇到的问题是,代码没有检查并粘贴到 MASTER 工作簿中的下一个可用行,而是检查源工作簿中的下一个可用行并粘贴到主工作簿中的相应行号.

这是我的 atm。请看


Open PathFile For Input As #1

Do Until EOF(1)

    Line Input #1, SourceFile

    Set Source = Workbooks.Open(SourceFile)

    With Source.Sheets("Action Tracker")
        lastRow = .Range("F" & .Rows.Count).End(xlUp).Row

        For i = 10 To lastRow
            If Len(Trim(.Range("F" & i).Value)) <> 0 Then
                If CopyRange Is Nothing Then
                    Set CopyRange = .Rows(i)
                Else
                    Set CopyRange = Union(CopyRange, .Rows(i))
                End If
            End If
        Next

        If Not CopyRange Is Nothing Then
            CopyRange.Copy ThisWorkbook.Sheets("MasterSheet").Rows(Range("F100000").End(xlUp).Offset(1, 0).Row)
        End If

    End With

    Source.Close SaveChanges:=False
    CB.Clear
    Set CopyRange = Nothing

Loop

错误在以下行中:

CopyRange.Copy ThisWorkbook.Sheets("MasterSheet").Rows(Range("F100000").End(xlUp).Offset(1, 0).Row)

Range 单独使用时(不是 something.Range),是 ActiveSheet.Range

的快捷方式

你可以试试这个:

With ThisWorkbook.Sheets("MasterSheet")
    CopyRange.Copy .Rows(.Range("F100000").End(xlUp).Offset(1, 0).Row)
End With