+ Reply to Thread
Results 1 to 14 of 14

Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

  1. #1
    Registered User
    Join Date
    04-14-2010
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    8

    Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    I would like to create a macro that imports 8 separate text files into two excel sheets in the same workbook (4 in each, see below for details). Pearson's code is almost exactly what I need, however I need to treat consecutive delimiters (space) as one.

    Up until the multiple file import issue explained briefly above, a previous post is exactly what I needed: http://www.excelforum.com/excel-prog...rs-as-one.html

    Pearson himself replied with a solution, however it didn't seem to work for me. I fully expect that I'm missing something very obvious here. I put his solution directly under the line he specified (as well as trying to put it directly after on the same line).

    However, when I do this I get "Run-time error '1004': Unable to get the Trim property of the WorksheetFunction class".

    So solving this would be my first hurdle.

    My second would be the part about the multiple file import.

    As I stated above, I need to take two sets of four different text files (so four on each sheet), import only columns 2-5 from each (though each one has 11) and put them side-by-side (with one column space between each) in the same worksheet, starting at row 6. So the appropriate data from file 1 would be stored in columns B-E, file 2 in G-J, etc. The second worksheet will function exactly as the first in the exact same format.

    Please excuse me if I could have more clearly re-worded the following. I find it confusing even to myself...

    I have a specific file path for the aforementioned files, and as this task must be repeated in the future I would like to add to Pearson's script another user-input that asks to specify two sets of two-letter folder names (e.g., TR and GB) for which to find the appropriate four files, which will only differ by these same two letters at the beginning of their file names (four with TR and four GB).

    Example: "TRfilename.txt" and "GBfilename.txt" would be in files "TR" and "GB", respectively.

    As if I wasn't asking enough, after this macro is finished importing each individual file, I would like to sort by the second column of the remaining data (column 3, as it were) by increasing values. After the sort is complete, I also need to search the data for the first row that contains a specific word in said second column and delete this row and every one below it.

    Sounds like a real challenge to me, but I wouldn't be surprised if I saw a solution from one of you experts, so thanks in advance for the help.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    I get "Run-time error '1004': Unable to get the Trim property of the WorksheetFunction class".
    Post the code.

    How long is the input string?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    04-14-2010
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    The longest string in the file is just over 100 characters long.


    Please Login or Register  to view this content.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    I can't imagine how that line can break. What's in WholeLine when it happens?

  5. #5
    Registered User
    Join Date
    04-14-2010
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    I can't really say. I'm not that experienced in VB.

    Perhaps you can dumb down your question a bit for me?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    See if this does what you need:
    Please Login or Register  to view this content.
    Last edited by shg; 04-14-2010 at 06:32 PM. Reason: fixed SEVERAL typos

  7. #7
    Registered User
    Join Date
    04-14-2010
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    I still get the "Run-time error '1004': Unable to get the Trim property of the WorksheetFunction class" error.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    Post the text file you're importing.

  9. #9
    Registered User
    Join Date
    04-14-2010
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    I'm not able to post the data as it's proprietary information.

    This is the longest line in the file (which is repeated at standard intervals):

    " XXXXXX xxxxxxx xxxxxxxxxx xxxxxxxx xxx Tue Apr 13 16:06:33 2010 "

    This line has no bearing or indicator of column widths, markers, etc. It's really just a program & time stamp, but as you can see there are a lot of spaces.

    There also seems to be a null-code character at the beginning (which didn't carry over in cut-paste to here).

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    That would probably do it.

    After the Line Input, you could try

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    04-14-2010
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    Hmm. This is a stubborn one. I still get the same error.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    I have no way to help without knowing what's in the string.

    Good luck.

  13. #13
    Registered User
    Join Date
    04-14-2010
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    OK, thanks anyway.

  14. #14
    Registered User
    Join Date
    04-14-2010
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Modifying Pearson's Code to "Treat consecutive delimiters as one"+remove columns

    Anyone else able to help please?

    I would be willing to use entirely new code if it were easier to get help that way.

+ Reply to Thread

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