View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Paige Paige is offline
external usenet poster
 
Posts: 270
Default Creating Custom Function - A Little Help Please!

Have been trying to write my first custom function, to determine if a year is
a leap year, using the following formula provided by Microsoft:

=IF(OR(MOD(A1,400)=0,AND(MOD(A1,4)=0,MOD(A1,100)< 0)),"Leap Year", "NOT a
Leap Year")

In my worksheet, for example, I plan to put the following formula in cell
B1: =if(LeapYear(A1) = "leap",c209/t13,b23*U14). I cannot get the custom
function (below) to work properly; it either comes back with an error,
returns 0, or the wrong answer. So far, I've got:

Public Function LeapYear(MyRange As Range) As Integer
Dim ActiveCell As Range
On Error GoTo LeapYearErr
Application.Volatile
LeapYear =
"=IF(OR(MOD(A1,400)=0,AND(MOD(A1,4)=0,MOD(A1,100)< 0)),""leap"",""not"")"
LeapYearErr:
Exit Function
End Function

Can someone advise what I'm doing wrong here?