2013-10-30 424 views
0

這裏是我的代碼和所有作品,但我無法將數據插入到活動工作表中的最後一個空白處。大膽的是什麼,我試圖做的,它失敗...Excel 2010將數據導入第一個空白單元格

Sub load_csv() 

Dim fStr As String 
Dim nextrow As Long 

With Application.FileDialog(msoFileDialogFilePicker) 
    .Show 
    If .SelectedItems.Count = 0 Then 
     MsgBox "Cancel Selected" 
     Exit Sub 
    End If 
    'fStr is the file path and name of the file you selected. 
    fStr = .SelectedItems(1) 
End With 

設置nextrow =範圍(單元格(Rows.Count, 「A」)。完(xlUp).Row + 1)

With ThisWorkbook.Sheets("TEST").QueryTables.Add(Connection:= _ 
"TEXT;" & fStr, Destination:=**nextrow**) 
    .Name = "CAPTURE" 
    .FieldNames = True 
    .RowNumbers = False 
    .FillAdjacentFormulas = False 
    .PreserveFormatting = True 
    .RefreshOnFileOpen = False 
    .RefreshStyle = xlInsertDeleteCells 
    .SavePassword = False 
    .SaveData = True 
    .AdjustColumnWidth = True 
    .RefreshPeriod = 0 
    .TextFilePromptOnRefresh = False 
    .TextFilePlatform = 437 
    .TextFileStartRow = 1 
    .TextFileParseType = xlDelimited 
    .TextFileTextQualifier = xlTextQualifierDoubleQuote 
    .TextFileConsecutiveDelimiter = False 
    .TextFileTabDelimiter = True 
    .TextFileSemicolonDelimiter = False 
    .TextFileCommaDelimiter = True 
    .TextFileSpaceDelimiter = False 
    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) 
    .TextFileTrailingMinusNumbers = True 
    .Refresh BackgroundQuery:=False 

End With 
End Sub 

回答

1
Set nextrow = Cells(Rows.Count, "A").End(xlUp).Offset(1) 
+0

謝謝。我看到它的一件事是在我這樣做後給我一個編譯錯誤。我錯過了什麼? – user2939057

+0

您將需要Dim nextrow作爲'Range'而不是'Long' – tigeravatar

相關問題