lush888222
07-19-2008, 09:30 PM
Hi,
geometric mean is assume you have the following 2 numbers in a excel column: 2, 8
geometric mean = (2*8)^(1/n)
n = 2, since there are 2 numbers, 2 and 8.
so, geometric mean = (2*8)^(1/2)=16^(1/2) = 4
geometric mean = nth root of multiple of n numbers.
so I have to write a simple VBA-excel code/function to find the geometric mean of any set of numbers in an excel column.
I write a code but it doesn't give me the correct answers, could you please help me to correct it?
Here it goes:
Option Explicit
Function Geometric(rs)
Dim Sum as single
Dim i As Integer
Dim n As Integer
n = rs.Count
For i = 1 To n
sum = sum + (rs(i)) ^ (1 / n)
Next i
Geometric = sum
End Function
geometric mean is assume you have the following 2 numbers in a excel column: 2, 8
geometric mean = (2*8)^(1/n)
n = 2, since there are 2 numbers, 2 and 8.
so, geometric mean = (2*8)^(1/2)=16^(1/2) = 4
geometric mean = nth root of multiple of n numbers.
so I have to write a simple VBA-excel code/function to find the geometric mean of any set of numbers in an excel column.
I write a code but it doesn't give me the correct answers, could you please help me to correct it?
Here it goes:
Option Explicit
Function Geometric(rs)
Dim Sum as single
Dim i As Integer
Dim n As Integer
n = rs.Count
For i = 1 To n
sum = sum + (rs(i)) ^ (1 / n)
Next i
Geometric = sum
End Function