+ Reply to Thread
Results 1 to 5 of 5

How to parse an inconsistent text string to multiple columns

  1. #1
    Registered User
    Join Date
    06-21-2019
    Location
    Canada
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    10

    Post How to parse an inconsistent text string to multiple columns

    Hi,

    I have a system that will download a CSV file with information.

    Problem: There is a column that will reads multiple times and address onto one text string in one cell. Sometimes there may be 1 address and 1 time and sometimes there may be 10 address with 10 times.

    What I'd like the formula to do: I'd like to have a formula automatically look at all the information and separate the data. I've slowly been chipping away at it but I am very slow.

    I was wondering if someone could guide me to a faster solution. I've attached a workbook with the first sheet showing how the data is outputted to how I want the data to show. The second sheet is pretty much useless but it shows you how little I've come so far.

    To anyone who can help, I'd greatly appreciate it.

    Thank you,

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to parse an inconsistent text string to multiple columns

    Hi.

    I have had a look at your data. and it seems pretty Straight Forward.

    Your Data Starts with Times like or 9a: 9:40a: 8:45a: 2p: So all you really need to do is replace each time ending with a: and p: with |a:| and |p:|

    Then use the Text to Columns function to split your data at each "|"

    The major hurdle we have is when the time and the preceding postal codes run into each other.

    So the Question is do all your postal codes have 6 alpha numerics?

    Paste this code into A Macro Module and run Macro1

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 02-21-2020 at 09:20 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    01-24-2020
    Location
    Belgium
    MS-Off Ver
    2013
    Posts
    95

    Re: How to parse an inconsistent text string to multiple columns

    Quote Originally Posted by aabr View Post
    Hi,

    I have a system that will download a CSV file with information.

    Problem: There is a column that will reads multiple times and address onto one text string in one cell. Sometimes there may be 1 address and 1 time and sometimes there may be 10 address with 10 times.

    What I'd like the formula to do: I'd like to have a formula automatically look at all the information and separate the data. I've slowly been chipping away at it but I am very slow.

    I was wondering if someone could guide me to a faster solution. I've attached a workbook with the first sheet showing how the data is outputted to how I want the data to show. The second sheet is pretty much useless but it shows you how little I've come so far.

    To anyone who can help, I'd greatly appreciate it.

    Thank you,
    I've managed to locate all "delimiters(i.e. a: p: )" with merely a single formula (String to be parsed in A1)
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    ouput array is like this,
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Pls refert to the cells in BLUE in the attached file

    Unfortunately, due to inconsistency of time delimiters, say "8:45a:", "9a:", "3:30p:", it's way too difficult to further process the string by a single formula with aforementioned delimiter array; at least, nearly impossible for me
    Nevertherless, hope my formula could be of help for u!

    Cheers!
    Attached Files Attached Files
    Last edited by ThxAlot; 02-23-2020 at 06:50 PM.

  4. #4
    Registered User
    Join Date
    06-21-2019
    Location
    Canada
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    10

    Re: How to parse an inconsistent text string to multiple columns

    Hi Everyone, Update on this post. Although your suggestions were great and one was too over my head to attempt I didn't really find my complete answer. In saying that I did take your advice and recorded a macro that would replace all a: and p: with | using the text to delimeter. I think my next step will be to use the script to find the postal codes in each column and delete anything after it. It isn't the perfect answer but it is better than nothing. Thanks again!
    Last edited by aabr; 03-04-2020 at 01:49 PM.

  5. #5
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: How to parse an inconsistent text string to multiple columns

    I've looked at your data. There's a possible complication to automating this. If a postal code ends with a 1 and the following time were 1a:, 1p:, 2a:, 2p: or any of those with :mm between hour and a or p, there's no way short of explicitly completing postal codes before parsing times to handle, for example, ..., ON, X3Y 2Z11:30p: correctly.

    Parsing full addresses will be rather difficult since not all addresses include province and postal code or state and zip code. Assuming the only instances in which a 1 could appear immediately before a time would be as the final character in a postal code, you could use regular expressions to handle this. That requires VBA.

    The approach I'd take is implementing a user-defined function with a reference to an external library, Micrisoft VBScript Regular Expressions 5.5.

    Please Login or Register  to view this content.
    Put this in a general VBA module in your workbook, and add a reference (in the VBA Editor, Tools - References) to the external library given above.

    Use this UDF in formulas like

    A10:
    =regexextract($A2,"([1-9]|1[0-2])(:\d\d)?[ap]: ",1)

    B10:
    =regexextract(REPLACE($A2,1,SUMPRODUCT(LEN($A10:A10)),""),
    "[^:]+(([A-Za-z ,.]+[A-Z]\d[A-Z] ?\d[A-Z]\d)|([A-Za-z ,.]+\d{5}(-\d{4})?))?(?=$|([1-9]|1[0-2])(:\d\d)?[ap]: )")


    C10:
    =regexextract(REPLACE($A2,1,SUMPRODUCT(LEN($A10:B10)),""),"([1-9]|1[0-2])(:\d\d)?[ap]: ")

    Select B10:C10, copy. Move to D10, paste. Move to F10, paste. And so on to the right on row 10.

    The A10 and C10 patterns locate hour (1 to 9 or 10 to 12) possibly followed by :mm then a or p followed by : and a space.

    The B10 pattern is more complicated. It looks for a string of characters other than : possibly followed by a Canadian province and postal code (string of letters, spaces, commas or periods followed by letter-digit-letter possibly a space digit-letter-digit) or a US state and a zip code (string of letters, spaces, comma or periods followed by 5 digits then possibly by a hyphen and 4 more digits). Then it looks for BUT DOES NOT MATCH the next time or end of string.

    Even using regular expressions, I can think of a few pathological incomplete addresses which could screw this up. That said, in my opinion, this sort of text parsing exercise is pointless without regular expressions.
    Last edited by hrlngrv; 02-26-2020 at 12:02 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extracting numbers and text from inconsistent text/number formatted string
    By Brandivil in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-25-2013, 01:46 PM
  2. Translating an inconsistent text string to time format.
    By graveyardshiftee in forum Excel General
    Replies: 2
    Last Post: 02-21-2012, 05:42 AM
  3. How To Parse Specific text from String Data
    By zaidan in forum Excel General
    Replies: 2
    Last Post: 04-08-2011, 04:34 AM
  4. How to parse a simple text string with VBA?
    By barryleajo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-29-2010, 06:33 AM
  5. Parse Text, Split to New Row, Multiple Columns
    By msbaker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2010, 02:01 PM
  6. Excel 2007 : Parse string of text from one cell
    By ssim in forum Excel General
    Replies: 3
    Last Post: 02-20-2009, 11:12 AM
  7. How do i parse a text string with a date?
    By powderwoo@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2006, 02:02 AM
  8. Parse a space delimited string into unique columns
    By erighter in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2005, 09:06 AM

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