Functions cannot change the content or format of a cell
They can return a value
Try this
Public Function AgeIt(mycell)
AgeIt = (Date - mycell.Value) / 365
End Function
In the worksheet call this with, for example, =AGEIT(A1)
See also:
1) David McRitchie's site on "getting started" with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm
2) The DATEDIF function
http://www.cpearson.com/excel/datedif.aspx
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
www.stfx.ca/people/bliengme
remove caps from email
"Max" <(E-Mail Removed)> wrote in message
news:21B62A9D-01F0-48D8-8FB6-(E-Mail Removed)...
> Am more familiar with Access, but have created a function in XL07 as
> follows:
>
> Public Function AgeIt()
> Selection.NumberFormat = "0.00"
> ActiveCell.FormulaR1C1 = "=(TODAY()-RC[-1])/365"
> AgeIt = ActiveCell.FormulaR1C1
> End Function
>
> to calculate a person's age when the birthday is in the cell to the left.
>
> When I select the function and insert it into a cell, I get =AgeIt() on
> the
> formula bar, but #VALUE! in the cell.
>
> What am I missing???
>
> Thanks in advance for your help.