I have populated a variant that is initially 1D from a worksheet using the Range.Value function. By the Split function this array then become a jagged array leaving me with an array like:
<table border="0" cellpadding="0" cellspacing="0" width="107"><tbody><tr style="height:15.0pt" height="20"><td class="xl63" style="height:15.0pt;width:80pt" height="20" width="107">f,g,h,k,l</td> </tr> <tr style="mso-height-source:userset;height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">a,b,c,d</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">m,n,o</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">x,4</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">i,y</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">r,t
...
</td> </tr> </tbody></table>
Now I'm not sure how I can loop through this array to work with individual values?
I tried a For loop but I don't know how to get Ubound to the number of columns of a given row. The numbers of columns varies between 0 and 20 (I'm guessing). As I only occasionally write code it could be very something simple so if anyone has a good reason for jagged arrays in VBA that might be enough.
For reference I am using it as part of a UDF and here is the part of the code I'm using to load it.
Thanks for taking a look at this. Any help/advice would be appreciated.
<table border="0" cellpadding="0" cellspacing="0" width="107"><tbody><tr style="height:15.0pt" height="20"><td class="xl63" style="height:15.0pt;width:80pt" height="20" width="107">f,g,h,k,l</td> </tr> <tr style="mso-height-source:userset;height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">a,b,c,d</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">m,n,o</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">x,4</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">i,y</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl64" style="height:15.0pt" height="20">r,t
...
</td> </tr> </tbody></table>
Now I'm not sure how I can loop through this array to work with individual values?
I tried a For loop but I don't know how to get Ubound to the number of columns of a given row. The numbers of columns varies between 0 and 20 (I'm guessing). As I only occasionally write code it could be very something simple so if anyone has a good reason for jagged arrays in VBA that might be enough.
For reference I am using it as part of a UDF and here is the part of the code I'm using to load it.
Code:
Dim ToGroups As Variant
ToGroups = Range(ToGroupsTop & ":" & ToGroupsBottom).Value
'Splits Togroups string into jagged array & fromgroup into array
'Main index starts at 1 and subarrays start at 0, Sorry!
For index1 = 1 To UBound(ToGroups)
ToGroups(index1, 1) = Split(ToGroups(index1, 1), ",")
Next