View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
John[_132_] John[_132_] is offline
external usenet poster
 
Posts: 30
Default how pass array to a function?

Yeah... have to explain more I guess. A number of times in the program
I'm writing I need to see if a a particular cell is a member of the
union of three different arrays. So I did the following:

Set Union1 = Application.Union(Array1(3),Array2(5),Array3(11))

Each array is an array of arrays (so to speak). The "3", "5" and "11"
would be indicated by variables.

Then, to see if a particular cell value (Say RangeToCheck) is in Union1
I just do:

Select Case Application.Intersect(RangeToCheck, Union1) Is Nothing
case true... etc
case false... etc


Looks great but the application.intersect just doesn't work. So now
instead of all that I could just use match or countif or a number of
other things every time but I would rather have a function then use 3
searches every time.

So... I want to pass all three arrays to the function along with the
RangeToCheck and get back a true or false.

John






Bob Phillips wrote:
You don't need a function, just use

If Not IsError(Application.Match(x,Array,0)) Then

'do something

But you can pass an array in a Function like so

Public Function MyFunction (x As Long, ary As Variant)
Dim n As Long

For n = LBound(Ary) To UBound(ary)

If x = Ary(n) Then

MyFunction = True
Exit Function
End If
Next n
End Function

HTH

Bob

"John" wrote in message
...
If you have an Array, say Array(9), how do you pass that information for a
function to use?

For example:
Public Function MyFunction(x as long) as Boolean
Dim n as Long
MyFunction=False
For n = 1 to 9
If Array(n) = x then MyFunction = True
Next
End Function

I know you can't have Public Function MyFunction(x as Long, Array() as
long) as Boolean"

But there has to be some way for public functions to access arrays outside
the function doesn't there?

Thanks

John