PDA

View Full Version : Solved: How to refer to a range?



shawrie777
11-22-2010, 02:41 PM
In excel 2010 I would like to be able to make a function which can refer to any amount of cells. By this I mean in the same way as the sum or average function do, for any selection I choose.

I hope that makes sense. Can anyone help with this?

Thanks

Bob Phillips
11-22-2010, 02:44 PM
Public Function myFunc(rng As Range) As Double
Dim cell As Range
dim tmp As Double

For Each cell in rng

tmp = tmp + cell.Value2
Next cell

myFunc = tmp
End Function