derekackerman
asked on
Harmonic Mean VBA Macro Excel
I need to comput the H.M. of a column of numbers, this doesn't work:
ActiveCell.Formula = "=rX/SUM(1/B2:B" & lrow & ")"
for each cell in row 2 to the last row, I need to sum the Reciprocals (1/cell value), and then divide that into the number of cells (N)
Or is there a built in function for it?
ActiveCell.Formula = "=rX/SUM(1/B2:B" & lrow & ")"
for each cell in row 2 to the last row, I need to sum the Reciprocals (1/cell value), and then divide that into the number of cells (N)
Or is there a built in function for it?
Sorry, the function name is HARMEAN()
BTW, you can also calculate harmonic means with an array formula. For example, this finds the harmonic
mean for A1:A5...
{=1/(SUM(1/A1:A5)/COUNT(A1 :A5))}
To enter an array formula, do not enter the curly braces, and hit Ctrl+Shift+Enter instead of Enter to finish it off.
Excel will then display those braces to indicate that it's an array formula.
mean for A1:A5...
{=1/(SUM(1/A1:A5)/COUNT(A1
To enter an array formula, do not enter the curly braces, and hit Ctrl+Shift+Enter instead of Enter to finish it off.
Excel will then display those braces to indicate that it's an array formula.
derekackerman,
So, in VBA, you can do this to get your array formula:
ActiveCell.FormulaArray = "=1/(SUM(1/B2:B" & lrow & ")/COUNT(B2:B" & lrow & "))"
Patrick
So, in VBA, you can do this to get your array formula:
ActiveCell.FormulaArray = "=1/(SUM(1/B2:B" & lrow & ")/COUNT(B2:B" & lrow & "))"
Patrick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I like the last answer the best!
If you are using the Analysis ToolPak, you will have the HARMMEAN() function, that will do this rather easily.
Regards,
Patrick