Results 1 to 3 of 3

read txt(csv) file with 68 fields and copy 6 fields to new workbook.

Threaded View

  1. #1
    Registered User
    Join Date
    04-07-2011
    Location
    Gent, Belgium
    MS-Off Ver
    Excel 2007
    Posts
    38

    Thumbs up read txt(csv) file with 68 fields and copy 6 fields to new workbook.

    Hi,

    First of all, if the title is not clear please feel free to propose a better title and I will change it.

    I've got a txt document (which is a kind of csv document). For example data-students.txt and each line has 67 comma's so it has 68 fields.
    I'm only interested in the following field nr's:
    field 66, 67, 68, 7, 8, 9 which are the ID, Name, address, postalcode, city, countrycode

    So I'd like to save these 6 fields(columns) in the order I mentioned above in a seperate student-list.txt file also delimeter seperated.
    The first line of data-students.txt can be skipped since it holds different names.
    I'm not even sure if the only way is to use an array or maybe it can be done without. My brain hurts when I think to much about it :-)

    Note: would it make a difference to the script to do the same when the data-students.txt are seperated with semi-comma's and also when it would be saved with semi-comma's.

    Thanks in advance.

    This is what I got so far but maybe you have a better idea/way:

    Sub makenewcsvlist()
        Dim csvFilename As String
        Dim actWorkbook As Workbook
        
        
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        
        
        csvFilename = "data-students.txt"
        Workbooks.OpenText Filename:=csvFilename, DataType:=xlDelimited, Semicolon:=True, Local:=True
        actWorkbook = ActiveWorkbook
        
    'skip first row 'select fields 66,67,67,7,8,9 till last row 'copy to new workbook 'save new workbook as student-list.txt (also semicomma as delimeter)
    actWorkbook.Close Application.ScreenUpdating = True End Sub





    Greets
    Last edited by gosa; 12-27-2011 at 07:15 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.6.0 RC 1