+ Reply to Thread
Results 1 to 6 of 6

Complex Parsing Question

  1. #1
    Registered User
    Join Date
    03-16-2013
    Location
    USA, Earth
    MS-Off Ver
    Office Pro 2010
    Posts
    3

    Complex Parsing Question

    I get spreadsheets with thousands of lines and one particular column that is a real pain in the ***. This column contains 4 dates, 2-4 times, and two cities with state abreviations. Sorting these is a nightmare. I was thinking of maybe writing something in python, but thought I would ask here first before I reinvent the wheel. I placed a couple of examples from this column below:

    2013-03-16 08:00:00.0 2013-03-18 10:26:38.0 ABERDEEN MD USA,2013-03-18 13:15:00.0 2013-03-18 13:15:00.0 HAGERSTOWN MD USA

    2013-03-21 2013-03-21 12:00:00.0 HANOVER PA USA,2013-03-21 15:00:00.0 2013-03-22 23:59:00.0 SUTHERLAND VA USA

    2013-03-18 09:00:00.0 2013-03-18 23:58:00.0 LOCK HAVEN PA USA,2013-03-18 09:01:00.0 2013-03-19 23:58:00.0 GORDONSVILLE VA USA

    So, ideally I want to make:
    1 column for the first date
    1 column for the first time...but it should be blank if the first time comes after the second date
    1 column for the second date, blank if it comes before the city name
    1 column for the second time, blank if it comes before the city name
    1 column for the first city name (might be multiple words)
    1 column for the first state abreviation
    1 column for the third date
    1 column for the third time
    1 column for the fourth date
    1 column for the fourth time
    1 column for the second city name
    1 column for the second city abreviation

    There are a few more things I would probably implement with a python script...but I figure this would get me close enough. Does Excel or OpenOfficeCalc or some other app have such functions built in, or are there free apps in the wild that will do this for me?

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Complex Parsing Question

    If you have the cell active then this will parse it:

    Please Login or Register  to view this content.
    Directions for running the routine(s) just supplied

    Copy the code to the clipboard

    Press ALT + F11 to open the Visual Basic Editor.

    Open a macro-enabled Workbook or save your Workbook As Macro-Enabled

    Select “Module” from the Insert menu

    Type "Option Explicit" then paste the code under it

    With the cursor between Sub and End Sub press F5 (F8 to Single Step)

    OR

    Press ALT + Q to close the code window.

    Press ALT + F8 then double click on the macro name

    BTW isn't it LOCKE HAVEN???
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    03-16-2013
    Location
    USA, Earth
    MS-Off Ver
    Office Pro 2010
    Posts
    3

    Re: Complex Parsing Question

    Wow...thank you. Now, if it isn't too much bother, how can I do it on lots of cells instead of 1 at a time 2800 times?


    Lock Haven, PA:
    http://goo.gl/maps/fgvDC

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Complex Parsing Question

    It depends on where they are. If, for instance, they are contiguous then:

    Please Login or Register  to view this content.
    And - You're welcome!

  5. #5
    Registered User
    Join Date
    03-16-2013
    Location
    USA, Earth
    MS-Off Ver
    Office Pro 2010
    Posts
    3

    Re: Complex Parsing Question

    Awesome...I never knew Excel had such features built in. Your new code gives error 28 after 349 lines, but I sorted it and it works good...I expected it to fail at 6980 lines, but it worked fine on a test of 11,000 lines...and that's several times the largest sheet I've gotten so far.

    Please Login or Register  to view this content.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Complex Parsing Question

    Glad to hear it - happy parsing!

+ 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