Display collection items from array function properly

simurq

Board Regular
Joined
Nov 11, 2011
Messages
73
My function returns an array which also have a collection (Col) as its last item:

Code:
For Each Node In Resp.getElementsByTagName("condition")
   cover = Node.Attributes.getNamedItem("cover").Text
            
   If Not Node.Attributes.getNamedItem("base") Is Nothing Then
      base = Node.Attributes.getNamedItem("base").Text
   Else: base = "0"
   End If

   Col.Add Array(cover, base)
Next Node

funcResult = Array(data1, data2, data3, data4, Col)

But when I run the Sub, I get "Runtime error 1004: Application-defined or object-defined error". I understand this is due to array "temp()"s size but how can I display the temp() values properly?

Code:
Sub Button_Click()    
    Dim getData as String
    Dim temp() As Variant
    Dim C As Integer
    
    Sheet1.Range("A:A").ClearContents
    getData = Sheet1.Range("A1").Value
    temp = funcResult(getData)
    C = UBound(temp)
    
    For i = 0 To C
        Sheet1.Cells(i + 1, 1).Value = temp(i)
    Next i
    
End Sub

Thanks!

Rustam
 
Last edited:
The order of elements and collections is up to you. The collection doesn't have to be the last element in the array.

The point is to loop through each element in the main array and use separate loops for the elements of sub-arrays or collections.
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,214,829
Messages
6,121,827
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top