+ Reply to Thread
Results 1 to 8 of 8

Extract Dates from String

  1. #1
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Extract Dates from String

    I want to be able to extract dates (where excel recognizes it as a date) from a string.

    Here are some samples:

    From JAN-01-2011 To JAN-15-2011
    From JAN-01-2010

    it will always be in one of those two formats but the dates will change.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Extract Dates from String

    Please Login or Register  to view this content.
    Here is one way to find the three dates.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Extract Dates from String

    Please Login or Register  to view this content.



  4. #4
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Re: Extract Dates from String

    Quote Originally Posted by snb View Post
    Please Login or Register  to view this content.
    snb,

    That works great!! You are the man. I just need to do three other things with it:

    1) They need to be saved in two separate variables
    2) They need to be in date format
    3) It also needs to work if the sting only has one date in it (like the example I gave) - I think this one, I can just use part of davegugg's code but if you can think of a more efficient way, then I am all ears.

    btw, davegugg thank you for your help too. I appreciate everyone's help. And you gave me a few ideas as well.
    Last edited by djblois1; 07-15-2011 at 01:19 PM.

  5. #5
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Re: Extract Dates from String

    Here is what I have so far:

    Please Login or Register  to view this content.
    I need to do 3 things with this code now:

    1) They need to be saved in two separate variables
    2) They need to be in date format
    3) It also needs to work if the sting only has one date in it (like the example I gave)

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Extract Dates from String

    The code I posted was already set up to do those three things:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Re: Extract Dates from String

    Thank you - it actually works great. Quick question:

    does this:

    Please Login or Register  to view this content.
    mean that I can use a stra(0), Stra(1), and a Stra(2)?

    if so why didn't you use:

    Please Login or Register  to view this content.
    Can I use that for any variable?

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Extract Dates from String

    It declares the variable as an array with three members. I really only needed two. You can easily find more info on vba arrays by doing a quick Google search. You could also set up the date variable as an array.

+ 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