+ Reply to Thread
Results 1 to 9 of 9

Finding a line in a text file, offset x rows, and copy everything else in the file

  1. #1
    Registered User
    Join Date
    09-11-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2002, 2003,2007
    Posts
    39

    Finding a line in a text file, offset x rows, and copy everything else in the file

    I have searched the forums, and have not been able to find quite what I'm looking for.

    I have a code that opens a text file, reads the whole thing in, then pastes to appropriate worksheets. However, I only want data starting after a particular row to the end of the file.

    The code is:
    Please Login or Register  to view this content.

    I can not attach the actual spreadsheet, as it's proprietary, but I have attached a text file that contains the data. Again, the code works to bring in the entire file, but I only want the data starting 3 rows after the row containing "Measur.;from;to..." (i.e. the row starting with "1;") However, I can't base it on the "1;" as that may not exist in the file, but the "Measur.;from;to..." will always be there.

    Thanks

    J
    Attached Files Attached Files
    Last edited by new.vbacoder; 10-27-2010 at 12:53 PM.

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Finding a line in a text file, offset x rows, and copy everything else in the fil

    You are using the QueryTables method that you will have to replace with methods to read the text file and do the necessary filtering and parsing. Are you familiar with that or do you need so help?
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  3. #3
    Registered User
    Join Date
    09-11-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2002, 2003,2007
    Posts
    39

    Re: Finding a line in a text file, offset x rows, and copy everything else in the fil

    I am still fairly new at the whole VBA coding. I'm getting the hang of the easy stuff, but when it comes to manipulating the data further than copy/paste, I'm a bit "green". Any help would be great.

    Just an update to my previous post, there may only be 5 data points, or hundreds, so the first part of the text file (up to the actual data) could be short, or very long. The only constant is the row containing "Measur.;from;to..."

    Thanks

    J

  4. #4
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Finding a line in a text file, offset x rows, and copy everything else in the fil

    Not a problem. I'll fix you up. Can you tell me what is in the cells A1:G1 in the Averages sheet?

  5. #5
    Registered User
    Join Date
    09-11-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2002, 2003,2007
    Posts
    39

    Re: Finding a line in a text file, offset x rows, and copy everything else in the fil

    That's the header I want to put in row 1 of each worksheet.

  6. #6
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Finding a line in a text file, offset x rows, and copy everything else in the fil

    try this out
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-11-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2002, 2003,2007
    Posts
    39

    Re: Finding a line in a text file, offset x rows, and copy everything else in the fil

    That worked, mostly.

    First, the values came in as text, not number. Second, in sheets R2-R13, the data below still remained (i.e. the text from the import did not get removed). However, looking over the code, the following should have been 1 to 13. After changing that, all the worksheets were good (except the text not number thing).

    Please Login or Register  to view this content.

    Where would I put a line to convert text to number?

    Thanks, you rock, by the way.

    J
    Last edited by new.vbacoder; 10-26-2010 at 02:42 PM.

  8. #8
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Finding a line in a text file, offset x rows, and copy everything else in the fil

    Oops, I forgot to change the 1 to a 13. I made the change while testing. Below is the changed code and the fix for the string rather than number problem. I am not sure why Excel didn't make the change itself. It is usually more clever than that.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    09-11-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2002, 2003,2007
    Posts
    39

    Re: Finding a line in a text file, offset x rows, and copy everything else in the fil

    That worked like a charm. Thanks for your assistance.

    J

+ 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