我的代码仅在导入后执行第一个循环上的格式化行,但之后不会执行它们。其他一切都有效。我已经多次擦洗它了。想法?如果有人需要更多我的代码剪辑,我可以添加它们。我对其他部分没有任何问题。
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个循环上运行,但之后再也不会运行。
答案 0 :(得分:0)
简而言之,这是一个简单的错误。 R值用于在上一个复制的部分之后计算和追加复制的单元格。这导致代码粘贴到下面,我没有找到它,因为代码也应该删除Run1上面的所有空单元格。
解决方案是删除R和相关代码以防止附加复制