+ Reply to Thread
Results 1 to 6 of 6

Getting a string that represents the date as it's displayed in the cell

  1. #1
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Getting a string that represents the date as it's displayed in the cell

    Hi

    I have a bunch of sheets with lots of dates on each sheet. My problem is some dates were entered as 2003/07/06 (yyyy/mm/dd) and others were entered as 06/07/2003 (dd/mm/yyyy) in the cells (the dates came from different sources and some of them were typed in as well). In all the cases the date is displayed as 06/07/2003 (dd/mm/yyyy). VBA is seeing both formats as dates but when working with the cells one is interpreted as 06/07/2003 and the other one is interpreted as 07/06/2003 because of the different formats in which it was entered.

    I want to make a subroutine in VBA that can go through all the sheets and make the dates the same but alas...

    Is there a way I can read the date from the cell into a text string as it is displayed in the cell?. If I can do this I can then force the date into a format that is consistent over all the cells.

    There is literally thousands of dates so changing them by hand is impossible.

    Or any other ideas on how I can get the dates in one format will be appreciated?

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Getting a string that represents the date as it's displayed in the cell

    Try this code:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Getting a string that represents the date as it's displayed in the cell

    I don't understand. Using the .NumberFormat returns "dd/mm/yyyy" for both types of dates, the ones entered as 2003/06/07 and 07/06/2003. How do I use it to turn a date entered as 07/06/2003 into 2003/06/07 so that it will conform with the other dates that was entered as 2003/06/07 in the first place?

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Getting a string that represents the date as it's displayed in the cell

    Hi Bezzie

    Without a Sample File it's a bit difficult to know what you're dealing with...perhaps this will give you a start.
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Getting a string that represents the date as it's displayed in the cell

    If you have data in A1 (Date or other data) then:

    Please Login or Register  to view this content.
    gets the value as displayed.
    Gary's Student

  6. #6
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Getting a string that represents the date as it's displayed in the cell

    Got it solved. VarType() function of VBA made a distinction between the two date formats so was able to 'see' which ones I needed to change. Used DateValue() with Mid() functions to convert the wrong ones. Thanks for the inputs.

+ 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. Change way date is displayed in cell....
    By howardrg in forum Excel General
    Replies: 10
    Last Post: 02-02-2012, 01:55 PM
  2. Evaluating a string that represents a variable name
    By geko63 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-11-2011, 06:40 PM
  3. UK Date not displayed correctly in cell
    By ES_Jake in forum Excel General
    Replies: 6
    Last Post: 10-09-2009, 04:36 PM
  4. Dates as String displayed as US and UK date
    By kanuvas in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-05-2009, 11:22 AM
  5. Replies: 0
    Last Post: 08-23-2005, 12:24 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