Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Need to pull info from a large number of text files in a directory  (Read 4672 times)

0 Members and 1 Guest are viewing this topic.

SEBNN



    Rookie

    Re: Need to pull info from a large number of text files in a directory
    « Reply #15 on: March 26, 2008, 09:26:53 AM »
    My solution to this problem was a little different, I used excel to open the text file, search for the line I needed, copy the line and then close the file after pasting the line to a new workbook that stayed open.  It was more than 3 lines of code though.

    Esentially with Excel already open with a workbook named ("results") it would open each text file in a new window and import it into the spreadsheet cells using a fixed column width as the columns are the same size.  then I did the following search in a for loop to find the last instance (I know how many there are ahead of time).

    cells.find(what:="what I was looking for", after:=activecell, lookin :=xlformulas, lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:=false, searchformat:=false).activate

    Then it selected the offset cell to pull the numeric value for some result and copied and pasted that to the original window.

    activecell.offset(0,1).select
    selection.copy
    windows("results").activate
    sheets("sheet1").selecte
    range("a" & rowcounter).select  'this counts the rows and places it in the next empty row (more code not shown)
    activesheet.paste
    windows("textfile").activate
    activewindow.close savechanges:=false

    rowcounter =1+rowcounter
    loop

    Just another way of doing it.  It does open and close a lot of excel windows, but I have found that this doesn't take too long as I am able to consitently pull out the values that I need and paste them into a spreadsheet which then goes on to graph the results for me.