+ Reply to Thread
Results 1 to 14 of 14

VBA to loop different length text dates to convert to Dates

  1. #1
    Registered User
    Join Date
    06-04-2016
    Location
    New York
    MS-Off Ver
    2016
    Posts
    17

    VBA to loop different length text dates to convert to Dates

    I get a CSV with multiply date columns like this
    6232016
    7312016
    10252016
    50216
    102315
    5316
    my current approach is to us a if len is and separate into three columns and then join then convert to date then repeat for all other columns of the different text lengths. I have been searching the internet with no luck so I figure I would ask in this forum.
    Looking for a better way to save me hours of pain

    any direction would be greatly appreciated.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to loop different length text dates to convert to Dates

    Welcome to the board.

    A
    B
    C
    1
    6232016
    23 Jun 2016
    B1: =--TEXT(A1, LOOKUP(LEN(A1), {4,5,7}, {"0-0-00","0-00-00","0-00-0000"}))
    2
    7312016
    31 Jul 2016
    3
    10252016
    25 Oct 2016
    4
    50216
    02 May 2016
    5
    102315
    23 Oct 2015
    6
    5316
    03 May 2016
    Last edited by shg; 06-04-2016 at 03:29 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    06-04-2016
    Location
    New York
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to loop different length text dates to convert to Dates

    wow, that is amazing, are those } arrays within the formula?
    I am forever grateful, you saved me hours from
    =IF(LEN(A1)=7,LEFT(A1,1),LEFT(A1,2))
    =IF(LEN(A1)=7,MID(A1,2,2),MID(A1,3,2))
    =RIGHT(A1,4)
    these formula
    This is genius SHG B1: =--TEXT(A1, LOOKUP(LEN(A1), {4,5,7}, {"0-0-00","0-00-00","0-00-0000"}))

    outstanding Thank you, Thank you

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to loop different length text dates to convert to Dates

    Literal arrays, yes.

    You're welcome.

  5. #5
    Registered User
    Join Date
    06-04-2016
    Location
    New York
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to loop different length text dates to convert to Dates

    shg

    Follow up Question if I may, how would I make that into a function and put it in my personal macro sheet so it is available all the time since I use it so much. Is that possible with an formula like this. Thanks again fantastic

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to loop different length text dates to convert to Dates

    Unless your workbooks already use VBA, it would be gratuitous to have to handle all the associated issues just to replace a simple formula with a user-defined function. Create a Word doc and use it as a formulary. Mine is 404 pages long as of today.

  7. #7
    Registered User
    Join Date
    06-04-2016
    Location
    New York
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to loop different length text dates to convert to Dates

    Thanks that's a great idea

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to loop different length text dates to convert to Dates

    You're welcome.

  9. #9
    Registered User
    Join Date
    06-04-2016
    Location
    New York
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to loop different length text dates to convert to Dates

    Since I fix dates daily, I was tired of copy and pasting formula so I created a loop. (I did start my word formula book)

    Here it is, I prompt for column of dates and where to put fixed dates or overwrite them.

    Please Login or Register  to view this content.

    Two things I want to work on.
    1. Copying result in cell not the formula (so I do not have to copy and paste as values
    2.They threw in another Date Day,Month 52016 with no day, just month and Year.

    any additional input would be greatly appreciated to work with this great formula from Shg

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to loop different length text dates to convert to Dates

    Please Login or Register  to view this content.
    Last edited by shg; 06-12-2016 at 05:32 PM.

  11. #11
    Registered User
    Join Date
    06-04-2016
    Location
    New York
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to loop different length text dates to convert to Dates

    Thanks shg

    That works great for everything but the Date Day,Month 52016 with no day, just month and Year.
    when I run the code it fixes all but makes 52016 into 5/20/2016 which is wrong. This is a weird format that come over in a csv

    everything else is perfect. Don't know how to even attach this one because that could be a 5/20/16 date but comes across as just a month year

    Thanks again for your help, direction and education

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to loop different length text dates to convert to Dates

    Then your data is ambiguous, and you need to fix it at the source.

  13. #13
    Registered User
    Join Date
    06-04-2016
    Location
    New York
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to loop different length text dates to convert to Dates

    For that your correct, everything else works great, just tested again. The month year I will deal with as they come, easy enough

    Thanks again for great solutions time savers, and fantastic formula and code

    Thanks shg,

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to loop different length text dates to convert to Dates

    You're very welcome.

+ 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. Convert European dates to Excel-read dates
    By thepinkgeologist in forum Excel General
    Replies: 1
    Last Post: 09-21-2015, 10:33 AM
  2. [SOLVED] Convert Text into Dates
    By Sophie.Durrant in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-21-2014, 11:12 AM
  3. Convert Text Dates, Perform Calculation, Convert back to Text
    By Orada in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2012, 05:25 PM
  4. [SOLVED] Request a Macro to Convert data into Dates (Multiple Dates Values separated by Line)
    By seenai in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2012, 02:28 AM
  5. Convert Dates in 2011:08:17 format into Dates in Excel
    By JessRI in forum Excel - New Users/Basics
    Replies: 12
    Last Post: 09-11-2012, 09:55 AM
  6. Replies: 1
    Last Post: 06-25-2012, 12:45 AM
  7. Convert Dates to text
    By lmullenjr in forum Excel General
    Replies: 3
    Last Post: 08-18-2006, 10:15 AM

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