PDA

View Full Version : [SOLVED:] turn formula to a vba function



lior03
08-01-2005, 12:40 PM
hello

the following formula return the first sunday of the month.

=DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(1+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)
how can i turn it into a vba udf.
maybe:

Function dado(d As Date)
dado = DateSerial(year(d), month(d), 1) + Application.WorksheetFunction.MOD _
(1 + 7 - Application.WorksheetFunction.Weekday(DateSerial(year(d), month(d), 1)), 7)
End Function
whats wrong
thanks

Bob Phillips
08-01-2005, 12:50 PM
Don't understand why you would want to do it, but this works for me


Function dado(d As Date)
dado = DateSerial(Year(d), Month(d), 1) + _
(1 + 7 - Weekday(DateSerial(Year(d), Month(d), 1)) Mod 7)
End Function