Passing an array as argument for custom Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to find out how to pass an array as an
argument for a custom function.
I have an array colors(1 to 10) and I want to pass the
whole array into a custom fundtion so I can use the array
within the function.

Thanks.
 
And how do I enter the argument when I use the function.
Can I just do:

zzz(colors())
 
When I do that, it seems to only pass the first item in
the array.
For example, lets say I have the following function and
procedure:

Sub test()
Dim colors(1 To 10) As Integer

For i = 1 To 10
colors(i) = i + 10
Next i
zzz(colors)
End Sub

Function zzz(ParamArray myarr() As Variant)
Range("B1") = myarr(1)
End Function

When I use myarr(0) in the zzz function, it works fine,
but when I try to use myarr(1), I get a "Subscript out of
range" message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top