View Single Post
  #5   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?

I am not familiar with the redim preserve myArray

Also not familar with the varArray as Variant.

Guess I am slowly learning here.
John


Jacob Skaria wrote:
Hi John

Check out the below procedure/function

Sub Macro()
Dim myArray() As Long
Dim n As Long

For n = 1 To 9
ReDim Preserve myArray(n)
myArray(n) = n
Next

MsgBox MyFunction(3, myArray)
End Sub

Public Function MyFunction(x As Long, varArray As Variant) As Boolean
Dim n As Long
For n = 1 To UBound(varArray)
If varArray(n) = x Then MyFunction = True: Exit For
Next
End Function