+ Reply to Thread
Results 1 to 4 of 4

Array changes dates stored as dates into text.

  1. #1
    Registered User
    Join Date
    08-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    6

    Array changes dates stored as dates into text.

    I've made a macro that pulls date-values out from one Array (SearchBondArray) if a certain condition is met. The loop then adds the date from one array to TempDateArray, while making sure that the TempDateArray is expanding as more dates are added.

    When the entire array is searched through, and no more dates are to be added. The Array is then pasted into a range in an Excel Sheet.

    The issue is that when the dates are pasted into the excel sheet, the format is no longer dates but Text. And thus the sorting formula in the end can't sort the data by most recent date.

    Any idea on how to make sure that the values posted are still formatted as dates?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Array changes dates stored as dates into text.

    Try using:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    08-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Array changes dates stored as dates into text.

    Thank you! That worked great!

    Mind telling me what adding the "2" after .value does? As opposed to just .value.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Array changes dates stored as dates into text.

    .Value2 returns Date values as their Double equivalent (which is how Excel internally works with dates) so rather than getting 02/07/2014 from a cell with today's date in as you would with .Value, .Value2 will return 41822. This value can't be misinterpreted, unlike a Date string, which VBA will interpret as a date using a US format if it can, or return Text if it can't.

    When you use Application.Transpose, the data in the array becomes Strings rather than Dates, so when it is put into the range, VBA will interpret 02/07/2014 as being 7th Feb 2014 and return that as a date, but a date like 23/02/2014 can't be interpreted as a US format date, so you get a "23/02/2014" as text.

+ 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] Marco to convert numbers stored as text to numbers and dates stored as text to numbers
    By a2424 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-22-2014, 10:19 AM
  2. Array formula to check if dates returned from another array formula falls between 2 dates
    By Atul Maskara in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-19-2014, 09:54 PM
  3. [SOLVED] Array of dates when tested shows no dates ......but there are dates
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-29-2012, 12:45 PM
  4. Replies: 8
    Last Post: 01-16-2011, 07:27 PM
  5. Converting numbers stored as dates to text in Excel
    By David from Furdale in forum Excel General
    Replies: 1
    Last Post: 07-17-2006, 01:40 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