View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Vasant Nanavati Vasant Nanavati is offline
external usenet poster
 
Posts: 1,080
Default Find size of array passed to user-defined function

Hi Cliff:

Public Function myfun(rData As Range)
Dim idx As Integer
For idx = 1 To rData.Cells.Count
' ... data(idx) ...
Next idx
' ...
End Function

Regards,

Vasant.

"Cliff" wrote in message
...
I'd like to write a function which accepts a list and
executes a for loop with operations on each element in
the list. I can't figure out how to get the size of the
list. For example, my call in an excel cell would be

=myfun(A1:A10)

and the VBA code is

Public Function myfun(data)
Dim idx As Integer

size = ???
For idx = 1 To size
... data(idx) ...
Next idx

How do I get the size of data (10 in this example)? It
would be nice if it worked for both horizontal and
vertical arrays, but I'll take either.

Thanks!