Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Age function how to

Will someone PLEASE tell me in detail exactly how to use the code below to
obtain a viable result.

Where do you put the code

How do you call it

From where

Thanks very much for any help you provide



Function Age(Date1 As Date, Date2 As Date) As String
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim Temp1 As Date
Temp1 = DateSerial(Year(Date2), Month(Date1), Day(Date1))
Y = Year(Date2) - Year(Date1) + (Temp1 Date2)
M = Month(Date2) - Month(Date1) - (12 * (Temp1 Date2))
D = Day(Date2) - Day(Date1)
If D < 0 Then
M = M - 1
D = Day(DateSerial(Year(Date2), Month(Date2) + 1, 0)) + D + 1
End If
Age = Y & " years " & M & " months " & D & " days"
End Function



--
Norton Virus checker 2003 says this email is clean


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Age function how to

Thanks a pile BUT.....

I still would like to kmow the following:
If I was using the VBA code How/where do I call it from
Thanks

"Dave Peterson" wrote in message
...
Without looking at your code, maybe you could use the undocumented (except

for
xl2k) worksheet function.

Well, it's actually nicely documented he
http://www.cpearson.com/excel/datedif.htm

And there is a VBA version (datediff) that is documented.


pcor wrote:

Will someone PLEASE tell me in detail exactly how to use the code below

to
obtain a viable result.

Where do you put the code

How do you call it

From where

Thanks very much for any help you provide

Function Age(Date1 As Date, Date2 As Date) As String
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim Temp1 As Date
Temp1 = DateSerial(Year(Date2), Month(Date1), Day(Date1))
Y = Year(Date2) - Year(Date1) + (Temp1 Date2)
M = Month(Date2) - Month(Date1) - (12 * (Temp1 Date2))
D = Day(Date2) - Day(Date1)
If D < 0 Then
M = M - 1
D = Day(DateSerial(Year(Date2), Month(Date2) + 1, 0)) + D + 1
End If
Age = Y & " years " & M & " months " & D & " days"
End Function

--
Norton Virus checker 2003 says this email is clean


--

Dave Peterson



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Age function how to

Chrissy has the answer, but use alt-F11 instead of just F11.

And you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

pcor wrote:

Thanks a pile BUT.....

I still would like to kmow the following:
If I was using the VBA code How/where do I call it from
Thanks

"Dave Peterson" wrote in message
...
Without looking at your code, maybe you could use the undocumented (except

for
xl2k) worksheet function.

Well, it's actually nicely documented he
http://www.cpearson.com/excel/datedif.htm

And there is a VBA version (datediff) that is documented.


pcor wrote:

Will someone PLEASE tell me in detail exactly how to use the code below

to
obtain a viable result.

Where do you put the code

How do you call it

From where

Thanks very much for any help you provide

Function Age(Date1 As Date, Date2 As Date) As String
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim Temp1 As Date
Temp1 = DateSerial(Year(Date2), Month(Date1), Day(Date1))
Y = Year(Date2) - Year(Date1) + (Temp1 Date2)
M = Month(Date2) - Month(Date1) - (12 * (Temp1 Date2))
D = Day(Date2) - Day(Date1)
If D < 0 Then
M = M - 1
D = Day(DateSerial(Year(Date2), Month(Date2) + 1, 0)) + D + 1
End If
Age = Y & " years " & M & " months " & D & " days"
End Function

--
Norton Virus checker 2003 says this email is clean


--

Dave Peterson


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Age function how to

Bugger - I knew I should have actually done it to
check what I wrote :-)

Thanks for the added info.

Chrissy.

Dave Peterson wrote
Chrissy has the answer, but use alt-F11 instead of just F11.



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
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM


All times are GMT +1. The time now is 01:11 AM.

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"