View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach[_3_] Otto Moehrbach[_3_] is offline
external usenet poster
 
Posts: 31
Default UDF, Type it or use Insert Function

Excel 2002, Win XP
I remember being told in the past that a UDF must be entered using the
function wizard (Insert Function dialog box) and that typing the function
into a cell would not work.
I have 3 UDFs below. The 3rd one uses the first 2. During development,
I was able to utilize either of the first 2 by typing them into a cell
manually. The 3rd one, no. The 3rd one required the function wizard to
make it work.
What is the rule that allows the first 2 to work (by typing direct) and
the 3rd one to require the function wizard. Thanks for your help as always.
For your information, this has to do with the military 8 digit date
format. Otto
Function DateFrom8(j As Range) As Date
DateFrom8 = DateSerial(Left(j, 4), Mid(j, 5, 2), Right(j, 2))
End Function

Function DateTo8(i As Date) As String
DateTo8 = Year(i) & _
IIf(Len(Month(i)) 1, Month(i), "0" & Month(i)) & _
IIf(Len(Day(i)) 1, Day(i), "0" & Day(i))
End Function

Function IncDate(k As Range) As String
Dim TheDate As Date
TheDate = DateFrom8(k)
'The "5" in the following line is actually a calculated variable.
'The "5" is used here for development purposes only'
TheDate = _
DateSerial(Year(TheDate), Month(TheDate) + 5, Day(TheDate))
IncDate = DateTo8(TheDate)
End Function