Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default average date / new function

Hello
A customer gives me the following data :
2003/01-12
2002/01-03
2002/10-12
....
....
....
I would like to insert a new column so the above data would be calculated as
followed :

2003/01-12 would become 01/07/2003
2002/01-03 would become 15/02/2002
2002/10-12 would become 15/11/2002

......
.....
.....
Can anybody give me a solution (macro, inserting a new function, etc..)?
Thank you.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default average date / new function

How does 2002/10-12 become 15/11/2002 ??


--
Gary''s Student


"dirk" wrote:

Hello
A customer gives me the following data :
2003/01-12
2002/01-03
2002/10-12
....
....
....
I would like to insert a new column so the above data would be calculated as
followed :

2003/01-12 would become 01/07/2003
2002/01-03 would become 15/02/2002
2002/10-12 would become 15/11/2002

......
.....
.....
Can anybody give me a solution (macro, inserting a new function, etc..)?
Thank you.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default average date / new function

Public Function DateFromRange(DateRange As String) As Date
' This returns a date variable; if you need text you can convert it and
format it
' NOTE: I do no error checking of the validity of the input string!

Dim TempStr As String, Month1 As Integer, Month2 As Integer
Dim ResultMonth As Integer, ResultDay As Integer

' Parse out the months
TempStr = Right(DateRange, Len(DateRange) - InStrRev(DateRange, "/"))
Month1 = Val(Left(TempStr, InStr(TempStr, "-")))
Month2 = Val(Right(TempStr, Len(TempStr) - InStrRev(TempStr, "-")))

' Determine if an even or odd number of months
' and figure the "midrange" value correspondingly
ResultMonth = Int((Month2 - Month1) / 2)
If (Month2 - Month1) / 2 = Int((Month2 - Month1) / 2) Then
ResultDay = 15
Else
ResultDay = 1
ResultMonth = ResultMonth + 1
End If
ResultMonth = Month1 + ResultMonth

DateFromRange = DateSerial(Left(DateRange, 4), ResultMonth, ResultDay)

End Function

--
- K Dales


"dirk" wrote:

Hello
A customer gives me the following data :
2003/01-12
2002/01-03
2002/10-12
....
....
....
I would like to insert a new column so the above data would be calculated as
followed :

2003/01-12 would become 01/07/2003
2002/01-03 would become 15/02/2002
2002/10-12 would become 15/11/2002

......
.....
.....
Can anybody give me a solution (macro, inserting a new function, etc..)?
Thank you.



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
AVERAGESIFS Function - average cells that fall within a date rangeand meet additional criteria SK08 Excel Worksheet Functions 3 March 12th 09 06:31 PM
Basing Average function range on Date? DangerMouse Excel Discussion (Misc queries) 4 June 20th 06 06:21 PM
Error Handling #N/A with AVERAGE Function - Average of values in Row Sam via OfficeKB.com Excel Worksheet Functions 13 July 31st 05 03:59 PM
I want to use the MATCH function with the AVERAGE function but I . Miguel Excel Worksheet Functions 2 April 23rd 05 05:29 PM
How do I nesting subtotal function within average function in Exc Amy Yeh Excel Worksheet Functions 4 January 19th 05 06:23 PM


All times are GMT +1. The time now is 12:19 PM.

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

About Us

"It's about Microsoft Excel"