LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
JE McGimpsey
 
Posts: n/a
Default

While you can use worksheet functions (see my other reply), which in
general are more efficient, you could make your UDF a bit more efficient
using the DateSerial method.

This routine also corrects the result if the 1904 date system is being
used:

Public Function myEOM(BaseDate As Date, AddMonths As Long) As Date
Dim dDateCorrection As Double
With Application
If TypeOf .Caller Is Range Then _
dDateCorrection = 1462 * .Caller.Parent.Parent.Date1904
End With
myEOM = DateSerial(Year(BaseDate), Month(BaseDate) + _
AddMonths + 1, 0) + dDateCorrection
End Function


In article .com,
"Blue Hornet" wrote:

Ronni,

I had a similar problem with EOMONTH not being able to compute in the
SAME spreadsheet on the SAME computer with the SAME version of Excel.
In other words, from time to time it would just fail to compute,
leaving me with a NAME? error--and I always have the Analysis TookPak
add-in active. I didn't get it, and it was driving me crazy.

So I wrote my own function and it seems to work okay. I haven't had
occasion to check its performance on other language versions, though.
Of course, it means the sheet has to be opened with "Macros Enabled",
but all of mine require that.

*************************************

Function myEOM(Target As Date, AddMonths As Integer) As Date
' Because the EOMONTH() function in the Analysis Toolpack is causing
grief
myYear = Year(Target)
myMonth = Month(Target)
myTotalMonths = ((myYear - 1900) * 12) + myMonth + AddMonths + 1

myYear = Int(myTotalMonths / 12) + 1900
If myTotalMonths Mod 12 < 0 Then
myMonth = myTotalMonths Mod 12
Else
myMonth = 12 'Months evenly divisible by 12 means = December
myYear = Year(Target)
End If

myEOM = DateValue(myMonth & "/1/" & myYear) - 1
End Function

 
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
I'm having problems with EOMONTH Ronni T. Vasquez M. Excel Worksheet Functions 2 August 22nd 05 04:42 PM
Excel Analysis Add-in EOMONTH generates #NAME? error Ray Excel Worksheet Functions 6 July 18th 05 07:00 PM
problems with Sharing excel files mmayfield Excel Discussion (Misc queries) 0 January 22nd 05 08:45 PM
Problems opening Excel files using DFS links Byron Excel Discussion (Misc queries) 2 January 1st 05 11:31 PM
Problems with Excel formulas when 2002 upgraded to XP Kathi McGraw Excel Worksheet Functions 0 November 16th 04 05:27 PM


All times are GMT +1. The time now is 07:52 AM.

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"