Error with passing collection as parameter

  • Thread starter Thread starter McManCSU
  • Start date Start date
M

McManCSU

I am trying to pass a collection to a sub but I keep getting thi
error:

Compile Error:
Argument not optional

The collection is a collection of strings filled like this:
For i = 0 To finalrow - 3
assyNums(i) = Range("C" & i + 2)
Next i

I use this command to call the sub:
"Matching (assyNums)"
where Matching is the sub and, assyNums is collection.

The Sub looks like this:
"Private Sub Matching(assyNums)"
- OR - (if i add optional)
"Private Sub Matching(Optional assyNums)"

Inside the sub all i really do, is a for loop that accesses ever
element, so like
"For i = 0 To assyNums.Count"

Any help would be greatly appreciated
 
The construct you describe is an array, not a collection.

this worked for me:

Sub AB()
Dim assyNums() As String
Dim finalrow As Long
finalrow = Cells(Rows.Count, 3).End(xlUp).Row
ReDim assyNums(0 To finalrow - 1)
For i = 0 To finalrow - 3
assyNums(i) = Range("C" & i + 2)
Next i
Matching assyNums
End Sub

Private Sub Matching(assyNums() As String)
For i = LBound(assyNums) To UBound(assyNums)
Debug.Print i, assyNums(i)
Next
End Sub
 
Ok, well youre right on that, but I want to be able hold user create
objects in a collection. What would i have to change to make tha
happen? Can I hold user created objects in an array
 

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