Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Convert formulae to UDF

=IF((ROUNDUP(MONTH(A1)/3,0)=1),"31/03/"&(YEAR(A1)),
IF((ROUNDUP(MONTH(A1)/3,0)=2),"30/06/"&(YEAR(A1)),
IF((ROUNDUP(MONTH(A1)/3,0)=3),"30/09/"&(YEAR(A1)),"31/12/"&(YEAR(A1)))))

I have the formulae that I want to convert to UDF and use it in my VBA
project.
Please let me know how do I write a function out of it.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Convert formulae to UDF

A literal translation:

Function dd(ByVal dte As Date) As Date
Dim rDate As Date
If ((Application.RoundUp(Month(dte) / 3, 0) = 1)) Then
rDate = "31/03/" & (Year(dte))
Else
If (Application.RoundUp(Month(dte) / 3, 0) = 2) Then
rDate = "30/06/" & (Year(dte))
Else
If (Application.RoundUp(Month(dte) / 3, 0) = 3) Then
rDate = "30/09/" & (Year(dte))
Else
rDate = "31/12/" & (Year(dte))
End If
End If
End If
dd = rDate
End Function

OR

Function ddx(ByVal dte As Date) As Date
edays = Array(31, 30, 30, 31)
n = Int((Month(dte) - 1) / 3)
ddx = Str(edays(n)) & "/" & Str((n + 1) * 3) & "/" & Year(dte)
End Function

HTH

"shantanu oak" wrote:

=IF((ROUNDUP(MONTH(A1)/3,0)=1),"31/03/"&(YEAR(A1)),
IF((ROUNDUP(MONTH(A1)/3,0)=2),"30/06/"&(YEAR(A1)),
IF((ROUNDUP(MONTH(A1)/3,0)=3),"30/09/"&(YEAR(A1)),"31/12/"&(YEAR(A1)))))

I have the formulae that I want to convert to UDF and use it in my VBA
project.
Please let me know how do I write a function out of it.


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Convert formulae to UDF

Thanks.
But the resulting figure is in numbers. How do I format it as a date?

Shantanu


Toppers wrote:
A literal translation:

Function dd(ByVal dte As Date) As Date
Dim rDate As Date
If ((Application.RoundUp(Month(dte) / 3, 0) = 1)) Then
rDate = "31/03/" & (Year(dte))
Else
If (Application.RoundUp(Month(dte) / 3, 0) = 2) Then
rDate = "30/06/" & (Year(dte))
Else
If (Application.RoundUp(Month(dte) / 3, 0) = 3) Then
rDate = "30/09/" & (Year(dte))
Else
rDate = "31/12/" & (Year(dte))
End If
End If
End If
dd = rDate
End Function

OR

Function ddx(ByVal dte As Date) As Date
edays = Array(31, 30, 30, 31)
n = Int((Month(dte) - 1) / 3)
ddx = Str(edays(n)) & "/" & Str((n + 1) * 3) & "/" & Year(dte)
End Function

HTH

"shantanu oak" wrote:

=IF((ROUNDUP(MONTH(A1)/3,0)=1),"31/03/"&(YEAR(A1)),
IF((ROUNDUP(MONTH(A1)/3,0)=2),"30/06/"&(YEAR(A1)),
IF((ROUNDUP(MONTH(A1)/3,0)=3),"30/09/"&(YEAR(A1)),"31/12/"&(YEAR(A1)))))

I have the formulae that I want to convert to UDF and use it in my VBA
project.
Please let me know how do I write a function out of it.



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Convert formulae to UDF

Format the cell as a date manually (format|cell|number tab)

shantanu oak wrote:

Thanks.
But the resulting figure is in numbers. How do I format it as a date?

Shantanu

Toppers wrote:
A literal translation:

Function dd(ByVal dte As Date) As Date
Dim rDate As Date
If ((Application.RoundUp(Month(dte) / 3, 0) = 1)) Then
rDate = "31/03/" & (Year(dte))
Else
If (Application.RoundUp(Month(dte) / 3, 0) = 2) Then
rDate = "30/06/" & (Year(dte))
Else
If (Application.RoundUp(Month(dte) / 3, 0) = 3) Then
rDate = "30/09/" & (Year(dte))
Else
rDate = "31/12/" & (Year(dte))
End If
End If
End If
dd = rDate
End Function

OR

Function ddx(ByVal dte As Date) As Date
edays = Array(31, 30, 30, 31)
n = Int((Month(dte) - 1) / 3)
ddx = Str(edays(n)) & "/" & Str((n + 1) * 3) & "/" & Year(dte)
End Function

HTH

"shantanu oak" wrote:

=IF((ROUNDUP(MONTH(A1)/3,0)=1),"31/03/"&(YEAR(A1)),
IF((ROUNDUP(MONTH(A1)/3,0)=2),"30/06/"&(YEAR(A1)),
IF((ROUNDUP(MONTH(A1)/3,0)=3),"30/09/"&(YEAR(A1)),"31/12/"&(YEAR(A1)))))

I have the formulae that I want to convert to UDF and use it in my VBA
project.
Please let me know how do I write a function out of it.



--

Dave Peterson
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
Recalculation of formulae disabled Astroskibiker Excel Discussion (Misc queries) 2 June 3rd 06 01:21 AM
Change to formulae Emma Hope Excel Worksheet Functions 3 September 5th 05 09:16 PM
Convert decimal degree (lattitude/longitude) into Degree, Tim Ashcom Excel Discussion (Misc queries) 5 August 17th 05 04:53 PM
CONVERT Function Disappered in Excel Gord Dibben Excel Discussion (Misc queries) 3 April 13th 05 07:59 PM
Convert Numeric into Text Monty Excel Worksheet Functions 0 December 18th 04 09:25 PM


All times are GMT +1. The time now is 10:53 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"