+ Reply to Thread
Results 1 to 5 of 5

Excel-represented dates vs. Human-readable dates in UDFs

  1. #1
    Registered User
    Join Date
    07-02-2014
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    33

    Excel-represented dates vs. Human-readable dates in UDFs

    Hello

    When you punch in a native function like
    Please Login or Register  to view this content.
    you get a human-readable output, like 2/23/15. Yet a barebones UDF will spit out the excel representation of a date like 42058.

    Here's a brief UDF for the sake of example. What am I missing of get a human-readable date as output that will still behave like an Excel date?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    13,462

    Re: Excel-represented dates vs. Human-readable dates in UDFs

    I would suggest a tutorial such as this http://www.cpearson.com/excel/datetime.htm to understand how Excel and VBA represent dates as a serial number. Recognize that the "human readable" output is merely an appropriate number format code applied to a cell containing an appropriate serial number.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    07-02-2014
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    33

    Re: Excel-represented dates vs. Human-readable dates in UDFs

    Quote Originally Posted by MrShorty View Post
    Recognize that the "human readable" output is merely an appropriate number format code applied to a cell containing an appropriate serial number.
    I suppose the heart of my question is why can a native formula like =TODAY() seem to know to change the number format code from "general" to "date" automatically, but my UDF requires me to change the number format code from "general" to "date" manually. My concern is for the general user of my UDF who will likely not realize that the serial number represents a date.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    13,462

    Re: Excel-represented dates vs. Human-readable dates in UDFs

    There are few things that native Excel functions can do that VBA UDFs cannot do, and I think this is one of them. Yes, with native functions, Excel will somehow "recognize" that a function's output should be date and will automatically format the cell for you. I don't think you can get VBA UDFs to do the same thing.

  5. #5
    Registered User
    Join Date
    07-02-2014
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    33

    Re: Excel-represented dates vs. Human-readable dates in UDFs

    Not the answer I was hoping to hear, but thank you for the information. I'm marking this one SOLVED.

+ 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. Replies: 5
    Last Post: 01-13-2015, 01:42 PM
  2. Macro to calculate Human readable date.
    By skalluri in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-04-2014, 05:02 AM
  3. Excel Dates copied from CSV file dont show as Dates
    By vew32 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2013, 09:30 AM
  4. Replies: 10
    Last Post: 09-04-2013, 08:34 PM
  5. [SOLVED] Auto filling dates based on previously entered dates and averaging numbers if dates equal
    By grambograham in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-11-2012, 03:21 PM

Tags for this Thread

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