none
Excel VBA Import data from another Excel CSV file RRS feed

  • Question

  • So i've have been trying to figure this one out for a while, the problem i keep facing with this is that i need to import around 10 thousand rows of data  reason being i have requirement to do so , i cannot use the inbuilt excel functions. Sorry im still new to excel and vba i would appreciate a little help, thank you in advance.
    Saturday, December 8, 2018 9:08 AM

All replies

  • Hi Venom,

    You can use the following code to import data from a CSV file into an Excel worksheet:

    Sub ImportCSVFile()
    'Updateby Extendoffice 20150909
        Dim xFileName As Variant
        Dim Rg As Range
        Dim xAddress As String
        xFileName = Application.GetOpenFilename("CSV File (*.csv), *.csv", , "Kutools for Excel", , False)
        If xFileName = False Then Exit Sub
        On Error Resume Next
        Set Rg = Application.InputBox("please select a cell to output the data", "Kutools for Excel", Application.ActiveCell.Address, , , , , 8)
        On Error GoTo 0
        If Rg Is Nothing Then Exit Sub
        xAddress = Rg.Address
        With ActiveSheet.QueryTables.Add("TEXT;" & xFileName, Range(xAddress))
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 936
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = True
            .TextFileSpaceDelimiter = False
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    

    For specific steps, please see the link below:

    How To Import Csv File Into Worksheet?

    Best Regards,

    Bruce


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, December 10, 2018 8:26 AM
    Moderator
  • Hi Venom,

    Have you solved your problem?

    Best Regards,

    Bruce


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Thursday, December 27, 2018 6:43 AM
    Moderator