简体   繁体   English

Excel 2010将数据导入第一个空白单元格

[英]Excel 2010 Importing Data into first blank cell

Here is my code and all works except I am unable to insert data to the last blank in the active worksheet. 这是我的代码,除无法将数据插入活动工作表中的最后一个空白外,所有工作均如此。 The bold is what I was trying to do and it is failing... 我试图做的是大胆的,但是失败了。

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

Set nextrow = Range(Cells(Rows.Count, "A").End(xlUp).Row + 1) 设置nextrow = Range(Cells(Rows.Count,“ A”)。End(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
Set nextrow = Cells(Rows.Count, "A").End(xlUp).Offset(1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM