Obtaining column/row numbers of cells in user defined function
- i guess your result could be now a Double and not a Long
- Also have you tried inserting some 'debug.print' lines for testing
- Could you please give a few examples of non-correct results.
Rewrite write result datatype change and debug.print. Also i have changed
SecondNumber to SecondNumber.Cells(1) to make sure a single value was
returned and not an array. Same with FirstNumber:
Function CumGrowth( _
SecondNumber As Range, _
FirstNumber As Range) As Double
Dim distance As Double
distance = SecondNumber.Cells(1).Row - FirstNumber.Cells(1).Row
CumGrowth = ((SecondNumber.Cells(1) / FirstNumber.Cells(1))) ^ (1 /
distance)
Debug.Print SecondNumber, FirstNumber, distance
End Function
--
Regards,
Sébastien
<http://www.ondemandanalysis.com
"GreenInIowa" wrote:
Hi Sebastien,
Thanks for the tip. I modified the function as you showed, but when I used
the "distance" with exponent the result is not correct. I was wondering if
"^" is not working as exponent in my computer. Thanks.
Function CumGrowth(SecondNumber As Range, FirstNumber As Range) As Long
distance = SecondNumber.Cells(1).Row - FirstNumber.Cells(1).Row
CumGrowth = ((SecondNumber / FirstNumber)) ^ (1 / distance)
End Function
"sebastienm" wrote:
Hi
1 .Using existing ROW( ) and COLUMN( ), it would be:
= Row(D5) - ROW(A1)
and
=COLUMN(D5)-COLUMN(A1)
2. Using a vba user defined func, it would be
Function RowDiff(Rg1 As Range, Rg2 As Range) As Long
RowDiff = Rg2.Cells(1).Row - Rg1.Cells(1).Row
End Function
and
Function ColDiff(Rg1 As Range, Rg2 As Range) As Long
ColDiff = Rg2.Cells(1).Column - Rg1.Cells(1).Column
End Function
--
Regards,
Sébastien
<http://www.ondemandanalysis.com
"GreenInIowa" wrote:
Hi,
I am writing a simple function which will use two cell values in Range("A1")
and Range("D5"). I would like to define the difference between them as a
distance in terms of columns and row numbers. I was wondering how I can get
the row/column numbers of two range parameters in a user defined function,
i.e., Function (A1, A2)
Thanks.
|