【问题标题】:Excel 2010 Importing Data into first blank cellExcel 2010 将数据导入第一个空白单元格
【发布时间】:2013-11-10 16:26:18
【问题描述】:

这是我的代码,除了我无法将数据插入活动工作表中的最后一个空白之外,所有的工作都有效。粗体是我试图做的,但它失败了......

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 = 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

【问题讨论】:

    标签: excel vba


    【解决方案1】:
    Set nextrow = Cells(Rows.Count, "A").End(xlUp).Offset(1)
    

    【讨论】:

    • 谢谢。我看到的一件事是在我这样做之后给我一个编译错误。我错过了什么?
    • 您需要将 nextrow 设置为 Range 而不是 Long
    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 2013-11-15
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    相关资源
    最近更新 更多