+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    05-26-2009
    Location
    Massachusetts, USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Converting LARGE text files to excel

    I am lookign for a way to convert text files with over 65000 lines of data to excel in a manner that would split the data to multiple worksheets. Does anybody know of a way to do this? Preferably a free way, but i'm open to other ideas.

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    2,807

    Re: Converting LARGE text files to excel

    This macro should do it, albeit slowly.

    Code:
    Sub Test()
    Open "C:\temp\mytextfile.txt" For Input As #1
    Do While Not EOF(1)
        Counter = Counter + 1
        Line Input #1, FileLine
        ActiveSheet.Cells(Counter, 1) = FileLine
        If Counter = 65000 Then
            Counter = 0
            Sheets.Add
        End If
    Loop
    Close #1
    End Sub
    Open up the VBA editor by hitting ALT F11

    Insert a new module by hitting Insert - Module

    Paste the macro into the empty sheet

    You will need to edit the path\filename.

    Hit ALT F11 to get back to the worksheet.

    Run the macro by going to tools-macro in Excel 2003 or the view ribbon in Excel 2007.
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

  3. #3
    Registered User
    Join Date
    05-26-2009
    Location
    Massachusetts, USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Converting LARGE text files to excel

    Ok, it's splittign the data into multiple sheets. That is great. However, it's not putting the data into separate cells. It's keeping each line separate, but it looks like the separation from one field to the next is being held with the small box character.

    The .txt file I'm trying to convert has blanks between data fields. There is no separator character. Is that part of the problem? It appears to be Tab-delimited.

  4. #4
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    2,807

    Re: Converting LARGE text files to excel

    You didn't mention how the lines were formatted. If there are not too many sheets, you could manually use the text to columns option to split.

    Otherwise, please post a small segment of the text file to allow for some experimentation.
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

  5. #5
    Registered User
    Join Date
    05-26-2009
    Location
    Massachusetts, USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Converting LARGE text files to excel

    Here is a small clip of the file format i am trying to convert. The software I use appears to only export text in this format.
    Attached Files Attached Files

  6. #6
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,477

    Re: Converting LARGE text files to excel

    ok i cobbled together this from above code
    it just uses the text to columns and autofit. i couldnt get beyond18 sheets without running out of memory tho (with either code)
    martin rice might have a better solution though
    Code:
    Sub Test()
    Application.ScreenUpdating = False
    Open "C:\Documents and Settings\Martin Wilson\Desktop\test[1].txt" For Input As #1
    Do While Not EOF(1)
        Counter = Counter + 1
        Line Input #1, FileLine
        ActiveSheet.Cells(Counter, 1) = FileLine
        If Counter = 65000 Then
          Columns("A:A").Select
        Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
            :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
            Array(7, 1))
       Cells.Select
        Cells.EntireColumn.AutoFit
            Counter = 0
            Sheets.Add
        End If
    Loop
    Close #1
      Columns("A:A").Select
        Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
            :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
            Array(7, 1))
       Cells.Select
        Cells.EntireColumn.AutoFit
        Application.ScreenUpdating = True
    End Sub
    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0