Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Simple UDF help

Hi I have the following simple UDF. How can I reference
the column numbers (the column in which they reside on the
worksheet) of the arguments "first" and "last" from inside
the function?

Function CAGR(first As Double, last As Double, n As
Integer)
CAGR = (last / first) ^ (1 / n) - 1
End Function

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Simple UDF help

since you are passing first and last as numbers, you can't. If you intend
to pass them is as range references, then you can redefine them as Ranges

Function CAGR(first As Range, last As Range, _
n As Integer)
dim firstColumn as Long, lastColumn as Long
firstColumn = first.Column
lastColumn = Last.Column
CAGR = (last.Value / first.Value) ^ (1 / n) - 1
End Function

Assumes first and last are single cell references.

--
Regards,
Tom Ogilvy



"Salman" wrote in message
...
Hi I have the following simple UDF. How can I reference
the column numbers (the column in which they reside on the
worksheet) of the arguments "first" and "last" from inside
the function?

Function CAGR(first As Double, last As Double, n As
Integer)
CAGR = (last / first) ^ (1 / n) - 1
End Function

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Simple UDF help

Salman,

If you want to reference the columns, you need to declare 'first'
and 'last' as Ranges. E.g.,

Function CAGR(first As Range, last As Range, n As Integer)
CAGR = (last / first) ^ (1 / n) - 1
Debug.Print first.Column, last.Column
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Salman" wrote in message
...
Hi I have the following simple UDF. How can I reference
the column numbers (the column in which they reside on the
worksheet) of the arguments "first" and "last" from inside
the function?

Function CAGR(first As Double, last As Double, n As
Integer)
CAGR = (last / first) ^ (1 / n) - 1
End Function

Thanks.



Reply
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
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Simple problem, simple formula, no FUNCTION ! Ron@Buy Excel Worksheet Functions 6 September 28th 07 04:51 PM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
Make it more simple or intuitive to do simple things Vernie Charts and Charting in Excel 1 March 16th 05 04:01 AM
simple question, hopefully a simple answer! Matt B Excel Programming 5 January 13th 04 08:43 PM


All times are GMT +1. The time now is 04:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"