Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Function return a Date, wrong format

Excel 2000 problem:


When putting in a cell a formula referring to a custom VBA function,
that returns a date or variant/date, the result is formatted as a
number.

When putting in a cell a std function like =TODAY(), the result is
formatted as a date.

Questions: does this problem occur in higher versions of Excel as well,
and is there maybe some way around?

I already tried to return a Variant/String containing the preformatted
date, but Excel does not recognize result as a date




'Results in the number "37987" appearing in the cell
Public Function TestDateFormat1() As Date
TestDateFormat1 = Date 'Returns the current system date
End Function

'Results in the number "37987" appearing in the cell
Public Function TestDateFormat2() As Variant
TestDateFormat2 = Date
End Function 'Results in 37987 in the cell


'Results in a left aligned string "2004/01/01" in the cell
Public Function TestDateFormat3() As Variant
TestDateFormat3 = Format(Date, "yyyy/mm/dd")
End Function


Many thanks


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Function return a Date, wrong format

When VBA returns a value to XL, it is parsed much like it would be
if you typed the result in by hand - the format displayed will be
the format of the cell, not of the entry.

Instead of formatting the result, just format the cell.



In article ,
kvdwerf wrote:

Excel 2000 problem:


When putting in a cell a formula referring to a custom VBA function,
that returns a date or variant/date, the result is formatted as a
number.

When putting in a cell a std function like =TODAY(), the result is
formatted as a date.

Questions: does this problem occur in higher versions of Excel as well,
and is there maybe some way around?

I already tried to return a Variant/String containing the preformatted
date, but Excel does not recognize result as a date




'Results in the number "37987" appearing in the cell
Public Function TestDateFormat1() As Date
TestDateFormat1 = Date 'Returns the current system date
End Function

'Results in the number "37987" appearing in the cell
Public Function TestDateFormat2() As Variant
TestDateFormat2 = Date
End Function 'Results in 37987 in the cell


'Results in a left aligned string "2004/01/01" in the cell
Public Function TestDateFormat3() As Variant
TestDateFormat3 = Format(Date, "yyyy/mm/dd")
End Function


Many thanks


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Function return a Date, wrong format

Thanks.
But this definitely is not sufficient. Try this in a cell

=TestNestedDateFunction(TestDateFormat1()),

with


Public Function TestNestedDateFunction(value As Variant) As String
TestNestedDateFunction = IIf(IsDate(value), "IsDate", "No
IsDate")
End Function


This results in a "Not IsDate", except for the third variant
TestDateFormat3.
And I really need an IsDate outcome, as well as a Date-value resultin
from a TestDateFormatX-cal

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
from date format convert to text format is wrong nooris Excel Discussion (Misc queries) 2 February 4th 10 03:41 PM
date in wrong format Mike New Users to Excel 3 November 15th 08 08:42 PM
Date in wrong format GKW in GA Excel Discussion (Misc queries) 6 February 19th 08 03:21 PM
Wrong date format in header Curt Charles PDX Excel Discussion (Misc queries) 1 October 25th 06 10:42 PM
YYYY format displaying wrong date Blaise Excel Discussion (Misc queries) 3 October 12th 05 02:28 AM


All times are GMT +1. The time now is 02:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"