为什么我的复制只适用于第一个循环?

Why does my Copying only work on the First Loop?

我的代码仅在导入后在第一个循环中执行格式化行,但之后任何时候都不会执行它们。其他一切都有效。我擦了好几次都没用。想法?如果有人需要我的代码的更多片段,我可以添加它们。我对其他部分没有问题。

Sub Main()
'this code imports one csv file at a time, analyzes it, determines individual run types and copies based on the type
Dim FName As Variant, R As Long, DirLoc As String, i As Integer
R = 1
i = 1
RowCount = 1
ColumnCount = 1
  DirLoc = ThisWorkbook.Path & "\" 'location of files
  FName = Dir(DirLoc & "*.csv")
    Do While FName <> ""
        ImportCsvFile DirLoc & FName, ActiveSheet.Cells(R, 1)
        R = ActiveSheet.UsedRange.Rows.Count + 1
        FName = Dir
        Sheets("RAW").Range("B1:B6").Copy
        Sheets("Filtered").Cells(RowCount, ColumnCount).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
            Application.CutCopyMode = False
            ColumnCount = ColumnCount + 6
        Set RangeObj = Cells.Find(What:="Run:", After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False)
            RangeObj.Select
            Range("A1:A" & ActiveCell.Row - 1).EntireRow.Delete
        For i = 1 To 100
            RunTypeChooser = 0
                    'Discover what format the csv file is in (depending on the run type). This may be edited to include more if needed
            DiscoverRunType
                    'Based on the discovery this will systematically copy a run with the appropriate run type, and delete the run
            CopyMain
            If Range("A1") = 0 Then
                Exit For
            End If
        Next i
        i = 1
        ColumnCount = 1
    Loop
End Sub

有问题的代码是这样的:

Sheets("RAW").Range("B1:B6").Copy Sheets("Filtered").Cells(RowCount, ColumnCount).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=True Application.CutCopyMode = False ColumnCount = ColumnCount + 6

它只会在第 1 个循环中 运行,但以后再也不会了。

简而言之,这是一个简单的错误。 R 值用于计算复制的单元格并将其附加到上一个复制的部分之后。这导致代码粘贴在下面,但我没有找到它,因为该代码还应该删除 Run1 上方的所有空单元格。

解决方案是删除 R 和相关代码以防止附加复制