+ Reply to Thread
Results 1 to 9 of 9

VBA Formatting

  1. #1
    Registered User
    Join Date
    07-20-2010
    Location
    liverpool
    MS-Off Ver
    Excel 2007
    Posts
    4

    VBA Formatting

    Can some one please help i am new to VBA but can read some code i am trying to format a cell from 20100730 to 2010-07-30 in a macro i have a sheet with about 14000 dates on that will need to be changed to this format in a text value to be uploaded in to a database.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: VBA Formatting

    Hi Collett, welcome to the forum.

    In your current data, are the dates actual dates or are they text that look like dates? You said they're currently YYYYMMDD - so is that a custom format of a real date, or just text?

  3. #3
    Registered User
    Join Date
    07-20-2010
    Location
    liverpool
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA Formatting

    they are just text format it is just a dump out of a old database.

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: VBA Formatting

    The quickest way would be to use a formula. Assuming your current values are in A1:A14000, then in B1 insert the formula:

    =LEFT(A1,4)&"-"&MID(A1,5,2)&"-"&RIGHT(A1,2)

    Fill that down to B14000. Copy B1:B14000, select A1 and use PasteSpecial -> Values. Delete column B.

    If you really need to use a macro, use:

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: VBA Formatting

    Here's a VBA solution
    Please Login or Register  to view this content.
    Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: VBA Formatting

    Chemist, I don't think just formatting the date is the key here, but I may be wrong. If the end result is to be able to import the column into a database that is expecting "date" values in yyyy-mm-dd format, Excel has to actually contain data stored as yyyy-mm-dd, not just dates formatted to show that way.

    I could be wrong.. only time and collett can say in this instance.

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: VBA Formatting

    Ahhh, I read it as the text dates were coming from a data base, not going to... Nevermind.

  8. #8
    Registered User
    Join Date
    07-20-2010
    Location
    liverpool
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA Formatting

    Thank you all for the replays i will test and let you know if it works

  9. #9
    Registered User
    Join Date
    07-20-2010
    Location
    liverpool
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA Formatting

    Thank you Paul works great you have been a great help and i know where to come for help from now on

+ 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