LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Create a user-defined function

Hi Max,

Here is a ay to do it:

Public Function AgeIt(ByRef rngMyCell As Range) As Double
AgeIt = (Date - rngMyCell.Value) / 365
End Function

This way you must use the function as:

=AgiIt(B6)

where B6 is the cell with the date in.

Firstly, you need to return something to the cell calling the function,
which you do with your final line, although your previous lines should not
work (unless being called from within code that has not been initiated by a
worksheet function. The reason is that worksheet functions can only return
values to a cell, but the worksheet (including the contents of the cell - the
formula) cannot be changed by a worksheet function. Therefore, the formatting
of the cell and attempting to enter a formula in the cell (which is
attempting to replace your AgeIt formula with "=(TODAY()-RC[-1])/365") will
not work.

If the cells are already in General format then you should see the result as
"0.00" anyway.

I hope this helps,

Sean.
--
(please remember to click yes if replies you receive are helpful to you)


"Max" wrote:

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.

 
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
How can I create a user defined function in excel? Martinj Excel Discussion (Misc queries) 4 August 20th 05 06:11 PM
Create User Defined Folder Delboy Excel Programming 1 February 8th 05 01:19 AM
How to create User Defined function in Excel Johnny Ko Excel Programming 2 December 5th 03 09:09 AM
How to create User Defined Function Warwick Renshaw Excel Programming 0 July 25th 03 07:15 AM
Create help for user-defined function Tom Ogilvy Excel Programming 0 July 12th 03 06:11 PM


All times are GMT +1. The time now is 12:42 PM.

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"