+ Reply to Thread
Results 1 to 3 of 3

Macro to collect data from a text file into an excel file

  1. #1
    Registered User
    Join Date
    05-01-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003
    Posts
    2

    Macro to collect data from a text file into an excel file

    Hi all,
    I am pretty new to this forum and request help on programming using vb in excel.

    I have the results of an analysis in text format (attached: suma.txt) which needs to be summarised in an excel file. I would like to have macro developed to capture the data in any specific format.

    The data of interest starts with the text 'Baseline draft:' and you can see that the data is repeated 13 times in the file. The data that is reported between the above text and the next repeat is of interest. if I take the first set, the values i need to capture in my summary table are: 5.699, 3.928, Fwd, 1.76, Stbd, 5.38, 4.872, 18519, 36.45, 5.38, 2.947, 48.59, 2.453. Similarly the corresponding values for the next 12 sets are also to be summarised.

    I am a novice to vb and has seen threads which touches similar requirement. Appreciate if someone can help with this.

    Thanking you in advance

    regards
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Macro to collect data from a text file into an excel file

    It's quite tricky to collect the data of interest because the file is in a partially unstructured format. There are 2 approaches I can think of, each based on finding specific known and consistent 'text markers' such as 'Baseline draft:' and 'Trim:' which occur in all 13 blocks of data (I haven't checked whether that is the case) and then parsing the line on which the marker occurs or the next line, etc.

    1. Read the file using Open and Line Input statements, parse each line using string functions like Instr (to find a text markers), Mid, Split, etc.

    2. Import the file into Excel (try opening the file in Excel which will start the Text Import Wizard and specifying the space delimiter, or no delimiters) and then use the VBA Find function (use the macro recorder whilst doing a manual Find to get the code syntax) to find the markers and then extract data from cells - maybe the required cells are consistent offsets from the found cell.
    Post responsibly. Search for excelforum.com

  3. #3
    Registered User
    Join Date
    05-01-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003
    Posts
    2

    Thumbs up Re: Macro to collect data from a text file into an excel file

    Thank you for the reply/ideas.

    I knew this would be tricky. All 13 blocks have the same consistent text markers with the required data occuring either alongside or below it. I am not sure which way to go but I will give both your ideas a try.

    Regards

+ Reply to Thread

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