ruedi
ruedi

Reputation: 5545

Loop over Collection of Collections

I have a collection of collections. The inner collections hold string items.

Filling inner Collection:

Function collect_excellent_Companies(ByVal folderName As String, ByVal fileName As String) As Collection
..
    Do While .Cells(countGreens, 1).Interior.Color = 65280
        myCol.Add CStr(.Cells(countGreens, 4).Value2)
        countGreens = countGreens + 1
    Loop
...
End Function

Filling the outer Collection:

For iRow = 1 To LastRow
     param1 = .Cells(iRow, 1).Value2 + "-Info"
     param2 = .Cells(iRow, 1).Value2
     fullCollection.Add collect_excellent_Companies(param1, param2)
Next iRow

Now I want to loop over the outer and inner collections with

Dim sepCol As Collection
Set sepCol = New Collection
Dim tmpCol As Collection
Set tmpCol = New Collection
Dim myStr As Object
'Loop over each competion
For Each sepCol In myCol
    For Each myStr In sepCol
            tmpCol.Add myStr
    Next myStr
next sepCol

I have checked the content of the collection before this loop and it is everything ok. The error I get is in the line:

For each myStr in sepCol 

Runtime Error 424: Object necessary. I already changed Dim myStr as String to Dim myStr as Object but this does not help. Any idea who I get this working would be very welcome!

Upvotes: 0

Views: 124

Answers (1)

ruedi
ruedi

Reputation: 5545

I found the solution myself.

I had to set

Dim myStr as Variant

Upvotes: 1

Related Questions