View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Peter Bradley Peter Bradley is offline
external usenet poster
 
Posts: 1
Default Using Ranges to input variables to UDF

Hi all,

I would like to use a range of cells in a UDF to input variables. A
trivial example, without using ranges, would be:

______________________________________

Function SimpleSum(s0,s1,s2,s3)

SimpleSum = (s0 + s2 + s3 + s4)

End Function
______________________________________


The input would be, "SimpleSum(A1,A2,A3,A4)", No problem!

However, what if I wanted to use a range. Here is an example just to
illiterate the problem. Why does the following function not work.

_______________________________________

Function SimpleAve(iSpike As Range)

Dim n As Integer
n = iSpike.Count

ReDim s(n)

i = 0
For Each cell In iSpike
s(i) = cell.Value
i = i + 1
Next cell

SimpleAve = (s0 + s1 + s2 + s3)/n

End Function
_________________________________________


I would like the input to be a range, i.e. SimpleAve(A1:A4)

Thanks in advance!
Peter