+ Reply to Thread
Results 1 to 5 of 5

Extract several dates from a string

  1. #1
    Registered User
    Join Date
    11-02-2008
    Location
    Melbourne
    Posts
    1

    Extract several dates from a string

    I have a spreadsheet with quantities and dates embedded in the text string. I would like to extract the Qty, Date, Qty, Date ... into up to 8 separate sets of columns so that I can work with the different dates and quantities separately.

    The data is currently in the following format, with the [701.4] being the Qty, followed by the date. Each separate Order #, Date & Qty are grouped in parenthesis ()

    (L-8735:3[701.4][22/09/2015])(L-8844:5[458.32][30/10/2015])
    (L-8744:5[935.2][22/09/2015])(L-8792:3[1402.8][29/10/2015])(L-8802:3[2104.2][29/10/2015])

    Can anyone recommend a macro to separate these or a formulae that may work

    Thanks
    Allen

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,051

    Re: Extract several dates from a string

    Hi, welcome to the forum

    Not VBA, but perhaps a slightly manual approach that may work for you.

    1. with your data in A2, copy this down in B2...
    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"(","@"),"[","@"),"]","@"),")","@")

    2. Copy/paste values either into a new column, or over the formulas
    3. Use Text2Columns/delimited/Other/@
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Extract several dates from a string

    VBA
    Please Login or Register  to view this content.

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Extract several dates from a string

    Maybe this one

    Enter formula in B2 and pull it to the right until you see blanks.

    =TRIM(MID(SUBSTITUTE("|"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A2,"[","|"),"]","|"),"(",""),")",""),"||","|"),"|",REPT(" ",255)),255*COLUMNS($A:A),255))

    SplitCell.JPG
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Registered User
    Join Date
    05-11-2015
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    27

    Re: Extract several dates from a string

    This is a great question, and if you would like to learn more about how the code below works you can learn about everything that's happening, line-by-line (and withe additional notes on how I landed on the RegExp matcher, for example), check out this post:

    How Can You Extract Several Values from a String?

    The macro below will pluck an arbitrary (meaning 2, or 3, or 4, or even up to 8 as you mentioned in your question) number of square bracket-enclosed values from the complicated strings you are facing.

    In order to run the script below, you'll need to ensure the "Microsoft VBScript Regular Expressions 5.5" library is enabled:

    turn_on_regular_expressions.png

    From there, this heavily-commented code should do the trick!

    Please Login or Register  to view this content.
    Attached Images Attached Images
    VBA demystified:
    HTML Code: 

+ 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. [SOLVED] Extract all the words from a string for processing, while leaving string intact.
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-10-2014, 02:02 PM
  2. [SOLVED] How to Extract A Number from String if Text within the String Equals XYZ
    By tyrsfury in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-15-2012, 03:30 PM
  3. [SOLVED] Extract a mainly numeric string (ISSN number) from an arbitrary string
    By Buzzed Aldrin in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-04-2012, 01:49 PM
  4. Replies: 16
    Last Post: 10-11-2011, 12:31 PM
  5. Extract Dates from String
    By djblois1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-15-2011, 02:31 PM
  6. Extract small string of text from larger string
    By mark_jam3s in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-23-2010, 05:36 AM
  7. Replies: 1
    Last Post: 08-23-2007, 01:10 PM

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