+ Reply to Thread
Results 1 to 7 of 7

Extract Substring, then Ignore that Substring, while collecting data from Other substrings

  1. #1
    Registered User
    Join Date
    04-16-2012
    Location
    US MS
    MS-Off Ver
    Excel 2010
    Posts
    3

    Extract Substring, then Ignore that Substring, while collecting data from Other substrings

    Ok this is a pretty complicated question. I am given a txt file "Data.txt". It has a lot of these lines

    [GPS: Central time,lat,dir,lon,dir,vel,cog,trk]
    135921.00,3609.75843,N,09008.86165,W,N,,29
    [GPS: Central time,lat,dir,lon,dir,vel,cog,trk]
    235921.00,3809.79843,S,09008.86165,W,N,.01,29

    What I'm wondering is how to extract each of the "Central Time" "lat" "dir" etc. from the file's first line. Then ignoring them for the rest of the file while still extracting each of the "135921.00" "3609.75843" "N" etc . I keep getting confused as to which variables I'm using or if I'm even using them correctly. Any help would be appreciated.

    Note - I already have the file opening, just need to know how to access the string/substrings. I'm also having to post the "Central Time" ect. as titles from A1-H1, as well as continuously post the data from An-Hn. In case anyone knows how to do that dynamically either.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Extract Substring, then Ignore that Substring, while collecting data from Other substr

    The simple Data TextToColumns functionality seems to provide all you need.
    Just copy the file into column A in a worksheet and specify the comma as a delimiter.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    04-16-2012
    Location
    US MS
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Extract Substring, then Ignore that Substring, while collecting data from Other substr

    I just tried to use the function, but I couldn't quite figure out how to do it with the variable of the different files that will be added. See most of it needs to be variables that just read in the title (which could change from file to file). The delimiter being "," was a good help though. Just can't figure out what looping style I need to use nor how to use it to extract the substring. Thank you though!

  4. #4
    Valued Forum Contributor
    Join Date
    12-05-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    308

    Re: Extract Substring, then Ignore that Substring, while collecting data from Other substr

    Hi Sameki

    I think you have three options:-
    1) A macro that reads the file line by line and parses the data (or ignores it) as appropriate.
    2) A macro that pre-processes the file, prior to import; or
    3) Read all the file in to a spreadsheet then delete the rows you don't want.

    I reckon Option 3 is probably the most reliable. The following code will clean out any rows with GPS in column A, but doesn't change Row 1, so leaves the headings intact.

    Please Login or Register  to view this content.
    Best regards, Rob.
    Last edited by rscsmith; 04-16-2012 at 07:00 PM. Reason: Forgot to turn on ScreenUpdating again!

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Extract Substring, then Ignore that Substring, while collecting data from Other substr

    Hello Sameki121,

    This macro may be what you want. It lets you choose the text file to open, the worksheet you want the output on, and the range where the output is to start. The header is copied only once.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Registered User
    Join Date
    04-16-2012
    Location
    US MS
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Extract Substring, then Ignore that Substring, while collecting data from Other substr

    Worked great Leith Ross thank you so much! RSCSmith your's worked too until I found out one of the requirements was that the sheet be cleared each run through, but thanks!

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Extract Substring, then Ignore that Substring, while collecting data from Other substr

    Hello Sameki121,

    You'e welcome. Glad to help.

+ 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