Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 06-11-2009, 02:42 PM
baldkat82 baldkat82 is offline
Registered User
 
Join Date: 26 May 2009
Location: Massachusetts, USA
MS Office Version:Excel 2003
Posts: 5
baldkat82 is becoming part of the community
Converting LARGE text files to excel

Please Register to Remove these Ads

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.
Reply With Quote
  #2  
Old 06-11-2009, 03:04 PM
mrice's Avatar
mrice mrice is offline
Forum Guru
 
Join Date: 22 Jun 2004
Location: Surrey, England
MS Office Version:Excel 2007
Posts: 1,842
mrice has been very helpful
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.
Reply With Quote
  #3  
Old 06-11-2009, 03:40 PM
baldkat82 baldkat82 is offline
Registered User
 
Join Date: 26 May 2009
Location: Massachusetts, USA
MS Office Version:Excel 2003
Posts: 5
baldkat82 is becoming part of the community
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.
Reply With Quote
  #4  
Old 06-11-2009, 05:27 PM
mrice's Avatar
mrice mrice is offline
Forum Guru
 
Join Date: 22 Jun 2004
Location: Surrey, England
MS Office Version:Excel 2007
Posts: 1,842
mrice has been very helpful
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.
Reply With Quote
  #5  
Old 06-12-2009, 01:21 PM
baldkat82 baldkat82 is offline
Registered User
 
Join Date: 26 May 2009
Location: Massachusetts, USA
MS Office Version:Excel 2003
Posts: 5
baldkat82 is becoming part of the community
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
File Type: txt test.txt (879 Bytes, 4 views)
Reply With Quote
  #6  
Old 06-12-2009, 03:16 PM
martindwilson's Avatar
martindwilson martindwilson is online now
Forum Guru
 
Join Date: 23 Jun 2007
Location: London,England
MS Office Version:office 97 ,2003 ( 2007 is now here. lol)
Posts: 5,686
martindwilson is a becoming a god in the Excel Forum World martindwilson is a becoming a god in the Excel Forum World martindwilson is a becoming a god in the Excel Forum World martindwilson is a becoming a god in the Excel Forum World martindwilson is a becoming a god in the Excel Forum World martindwilson is a becoming a god in the Excel Forum World
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


recommended reading
wiki Mojito

how to say no convincingly

most important think you need
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump