<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347427#M78581</link>
    <description>The correct syntax is ExcelList(2).Item(3)  However, the problem that you&lt;BR /&gt;
are experiencing is that everything you add to the RowList collection is&lt;BR /&gt;
immediately removed.  Your logic for storing your data is dead on center.&lt;BR /&gt;
You just need to use the right tools.  You can either create a new&lt;BR /&gt;
collection for each RowList or my suggestion is to create a class object.&lt;BR /&gt;
This is a bare bones class with no error checking.  After you've pasted the&lt;BR /&gt;
code into the class module and renamed it, run the test sub.  It'll print 6&lt;BR /&gt;
in the Immediate window, the 3rd Item in the 2nd 'List'.&lt;BR /&gt;
&lt;BR /&gt;
Public Sub test()&lt;BR /&gt;
  Dim rno As Integer, cno As Integer, tno As Integer&lt;BR /&gt;
  Dim oRowList As RowList, ExcelList As New Collection&lt;BR /&gt;
  tno = 1&lt;BR /&gt;
  For rno = 1 To 3&lt;BR /&gt;
    Set oRowList = New RowList&lt;BR /&gt;
    For cno = 1 To 3&lt;BR /&gt;
      'I changed it from Str() to the newer CStr() func.&lt;BR /&gt;
      oRowList.Add CStr(tno)&lt;BR /&gt;
      tno = 1 + tno&lt;BR /&gt;
    Next cno&lt;BR /&gt;
    ExcelList.Add oRowList&lt;BR /&gt;
&lt;BR /&gt;
    Set oRowList = Nothing&lt;BR /&gt;
  Next rno&lt;BR /&gt;
&lt;BR /&gt;
  Debug.Print ExcelList(2).Item(3)&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'Paste this code into a class module&lt;BR /&gt;
'and name it RowList&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
Private colRow As Collection&lt;BR /&gt;
&lt;BR /&gt;
Private Sub Class_Initialize()&lt;BR /&gt;
    Set colRow = New Collection&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Private Sub Class_Terminate()&lt;BR /&gt;
    Set colRow = Nothing&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Public Sub Add(ByVal Item As Variant)&lt;BR /&gt;
    colRow.Add Item&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Public Function Item(ByVal key As Variant) As Variant&lt;BR /&gt;
    Item = colRow.Item(key)&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
--&lt;BR /&gt;
Happy Holidays...&lt;BR /&gt;
Bobby C. Jones&lt;BR /&gt;
http://www.acadx.com</description>
    <pubDate>Thu, 20 Dec 2001 10:09:23 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2001-12-20T10:09:23Z</dc:date>
    <item>
      <title>Nested collections?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347421#M78575</link>
      <description>I have a collection which contains multiple collections inside and I was wondering how to access each item of the nested collection. For example list1 would be ((1 2 3),(4 5 6)) and if I wanted to access item 4 of the second list what would be the syntax? I tried list1(2)(1) but it didn't work.</description>
      <pubDate>Wed, 19 Dec 2001 15:36:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347421#M78575</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-19T15:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Nested collections?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347422#M78576</link>
      <description>&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;BR /&gt;
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"&amp;gt;&lt;BR /&gt;
  &lt;DIV&gt;"GARY NTX" &amp;lt;&lt;A href="mailto:gadamson@psp.com"&gt;gadamson@psp.com&lt;/A&gt;&amp;gt; &lt;BR /&gt;
  wrote in message &lt;A&gt;&lt;BR /&gt;
  href="news:f0a4244.-1@WebX.maYIadrTaRb"&amp;gt;news:f0a4244.-1@WebX.maYIadrTaRb&lt;/A&gt;...&lt;/DIV&gt;&lt;BR /&gt;
  &lt;DIV&gt;I have a collection which contains multiple collections inside and I was &lt;BR /&gt;
  wondering how to access each item of the nested collection. For example list1 &lt;BR /&gt;
  would be ((1 2 3),(4 5 6)) and if I wanted to access item 4 of the second list &lt;BR /&gt;
  what would be the syntax? I tried list1(2)(1) but it didn't work.&lt;/DIV&gt;&lt;BR /&gt;
  &lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;
  &lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;list1(2)(0) &lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;
  &lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 20 Dec 2001 05:30:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347422#M78576</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T05:30:54Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347423#M78577</link>
      <description>That doesn't work either...I get errors when I try that.I guess there is no way to have a collection inside a collection because the internal items can't be accessed.</description>
      <pubDate>Thu, 20 Dec 2001 07:42:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347423#M78577</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T07:42:44Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347424#M78578</link>
      <description>You can access nested collections.&lt;BR /&gt;
&lt;BR /&gt;
Public Sub test()&lt;BR /&gt;
    Dim colOne As Collection&lt;BR /&gt;
    Dim colTwo As Collection&lt;BR /&gt;
&lt;BR /&gt;
    Set colOne = New Collection&lt;BR /&gt;
    Set colTwo = New Collection&lt;BR /&gt;
&lt;BR /&gt;
    colTwo.Add Item:="ItemOne", Key:="kOne"&lt;BR /&gt;
    colTwo.Add Item:="ItemTwo", Key:="kTwo"&lt;BR /&gt;
    colTwo.Add Item:="ItemThree", Key:="kThree"&lt;BR /&gt;
&lt;BR /&gt;
    colOne.Add Item:=colTwo, Key:="kOne"&lt;BR /&gt;
    colOne.Add Item:=colTwo, Key:="kTwo"&lt;BR /&gt;
&lt;BR /&gt;
    'print the second item of the first nested collection&lt;BR /&gt;
    'via a position index&lt;BR /&gt;
    Debug.Print colOne(1).Item(2)&lt;BR /&gt;
&lt;BR /&gt;
    'print the third item of the second nested collection&lt;BR /&gt;
    'via a specific key value&lt;BR /&gt;
    Debug.Print colOne("kTwo").Item("kThree")&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
--&lt;BR /&gt;
Happy Holidays...&lt;BR /&gt;
Bobby C. Jones&lt;BR /&gt;
http://www.acadx.com</description>
      <pubDate>Thu, 20 Dec 2001 08:14:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347424#M78578</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T08:14:41Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347425#M78579</link>
      <description>OK your program works, but I can't seem to get mine to work although it&lt;BR /&gt;
seems to be syntaxed right.&lt;BR /&gt;
 Please see comment (1).&lt;BR /&gt;
&lt;BR /&gt;
Public Sub test()&lt;BR /&gt;
  Dim rno As Integer, cno As Integer, tno As Integer&lt;BR /&gt;
  Dim RowList As New Collection, ExcelList As New Collection&lt;BR /&gt;
  tno = 1&lt;BR /&gt;
  For rno = 1 To 3&lt;BR /&gt;
    For cno = 1 To 3&lt;BR /&gt;
      RowList.Add Str(tno)&lt;BR /&gt;
      tno = 1 + tno&lt;BR /&gt;
    Next cno&lt;BR /&gt;
    ExcelList.Add RowList&lt;BR /&gt;
    For cno = 1 To RowList.Count&lt;BR /&gt;
      RowList.Remove 1&lt;BR /&gt;
    Next cno&lt;BR /&gt;
&lt;BR /&gt;
    '(1) ExcelList should be = (("1","2","3"),("4","5","6"),("7","8","9"))&lt;BR /&gt;
    'so if I wanted to get "6", which item 3 in collection 2 what is the&lt;BR /&gt;
syntax?&lt;BR /&gt;
    'I tried ExcelList(2).Item(3), ExcelList(2)(3) and ExcelList(2).(3) to&lt;BR /&gt;
no avail&lt;BR /&gt;
&lt;BR /&gt;
  Next rno&lt;BR /&gt;
End Sub</description>
      <pubDate>Thu, 20 Dec 2001 09:06:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347425#M78579</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T09:06:13Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347426#M78580</link>
      <description>If you set a break point and step through your procedure in the debugger&lt;BR /&gt;
looking at the Locals window, you will see that when you remove the items&lt;BR /&gt;
for RowList it also removes the same nested items from ExcelList - when it&lt;BR /&gt;
is done ExcelList is empty.&lt;BR /&gt;
&lt;BR /&gt;
In place of the Remove loop, try&lt;BR /&gt;
&lt;BR /&gt;
    Set RowList = Nothing&lt;BR /&gt;
&lt;BR /&gt;
I haven't used nested collections so I don't know if this is the proper&lt;BR /&gt;
thing to do but, it works.&lt;BR /&gt;
&lt;BR /&gt;
Glen&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"GARYNTX" &lt;GADAMSON&gt; wrote in message&lt;BR /&gt;
news:0924A11C3069752D7CC9A56216D8DE30@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; OK your program works, but I can't seem to get mine to work although it&lt;BR /&gt;
&amp;gt; seems to be syntaxed right.&lt;BR /&gt;
&amp;gt;  Please see comment (1).&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Public Sub test()&lt;BR /&gt;
&amp;gt;   Dim rno As Integer, cno As Integer, tno As Integer&lt;BR /&gt;
&amp;gt;   Dim RowList As New Collection, ExcelList As New Collection&lt;BR /&gt;
&amp;gt;   tno = 1&lt;BR /&gt;
&amp;gt;   For rno = 1 To 3&lt;BR /&gt;
&amp;gt;     For cno = 1 To 3&lt;BR /&gt;
&amp;gt;       RowList.Add Str(tno)&lt;BR /&gt;
&amp;gt;       tno = 1 + tno&lt;BR /&gt;
&amp;gt;     Next cno&lt;BR /&gt;
&amp;gt;     ExcelList.Add RowList&lt;BR /&gt;
&amp;gt;     For cno = 1 To RowList.Count&lt;BR /&gt;
&amp;gt;       RowList.Remove 1&lt;BR /&gt;
&amp;gt;     Next cno&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;     '(1) ExcelList should be = (("1","2","3"),("4","5","6"),("7","8","9"))&lt;BR /&gt;
&amp;gt;     'so if I wanted to get "6", which item 3 in collection 2 what is the&lt;BR /&gt;
&amp;gt; syntax?&lt;BR /&gt;
&amp;gt;     'I tried ExcelList(2).Item(3), ExcelList(2)(3) and ExcelList(2).(3) to&lt;BR /&gt;
&amp;gt; no avail&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;   Next rno&lt;BR /&gt;
&amp;gt; End Sub&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/GADAMSON&gt;</description>
      <pubDate>Thu, 20 Dec 2001 09:57:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347426#M78580</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T09:57:21Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347427#M78581</link>
      <description>The correct syntax is ExcelList(2).Item(3)  However, the problem that you&lt;BR /&gt;
are experiencing is that everything you add to the RowList collection is&lt;BR /&gt;
immediately removed.  Your logic for storing your data is dead on center.&lt;BR /&gt;
You just need to use the right tools.  You can either create a new&lt;BR /&gt;
collection for each RowList or my suggestion is to create a class object.&lt;BR /&gt;
This is a bare bones class with no error checking.  After you've pasted the&lt;BR /&gt;
code into the class module and renamed it, run the test sub.  It'll print 6&lt;BR /&gt;
in the Immediate window, the 3rd Item in the 2nd 'List'.&lt;BR /&gt;
&lt;BR /&gt;
Public Sub test()&lt;BR /&gt;
  Dim rno As Integer, cno As Integer, tno As Integer&lt;BR /&gt;
  Dim oRowList As RowList, ExcelList As New Collection&lt;BR /&gt;
  tno = 1&lt;BR /&gt;
  For rno = 1 To 3&lt;BR /&gt;
    Set oRowList = New RowList&lt;BR /&gt;
    For cno = 1 To 3&lt;BR /&gt;
      'I changed it from Str() to the newer CStr() func.&lt;BR /&gt;
      oRowList.Add CStr(tno)&lt;BR /&gt;
      tno = 1 + tno&lt;BR /&gt;
    Next cno&lt;BR /&gt;
    ExcelList.Add oRowList&lt;BR /&gt;
&lt;BR /&gt;
    Set oRowList = Nothing&lt;BR /&gt;
  Next rno&lt;BR /&gt;
&lt;BR /&gt;
  Debug.Print ExcelList(2).Item(3)&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'Paste this code into a class module&lt;BR /&gt;
'and name it RowList&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
Private colRow As Collection&lt;BR /&gt;
&lt;BR /&gt;
Private Sub Class_Initialize()&lt;BR /&gt;
    Set colRow = New Collection&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Private Sub Class_Terminate()&lt;BR /&gt;
    Set colRow = Nothing&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Public Sub Add(ByVal Item As Variant)&lt;BR /&gt;
    colRow.Add Item&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Public Function Item(ByVal key As Variant) As Variant&lt;BR /&gt;
    Item = colRow.Item(key)&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
--&lt;BR /&gt;
Happy Holidays...&lt;BR /&gt;
Bobby C. Jones&lt;BR /&gt;
http://www.acadx.com</description>
      <pubDate>Thu, 20 Dec 2001 10:09:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347427#M78581</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T10:09:23Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347428#M78582</link>
      <description>Ya, or you could just do what Glen said &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  Although you have to admit that&lt;BR /&gt;
it's not as cool as creating your own custom objects.&lt;BR /&gt;
--&lt;BR /&gt;
Happy Holidays...&lt;BR /&gt;
Bobby C. Jones&lt;BR /&gt;
http://www.acadx.com</description>
      <pubDate>Thu, 20 Dec 2001 11:12:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347428#M78582</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T11:12:05Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347429#M78583</link>
      <description>WOW! I am new to this VB stuff and I didn't know about the Locals window or the Watch window, so I didn't know what was happening to my program. That makes debugging incredibly easier.</description>
      <pubDate>Thu, 20 Dec 2001 12:40:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347429#M78583</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T12:40:23Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347430#M78584</link>
      <description>Eek-gads man!!  Reminds me of the good old days of debugging lisp without&lt;BR /&gt;
the vlide &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
--&lt;BR /&gt;
Happy Holidays...&lt;BR /&gt;
Bobby C. Jones&lt;BR /&gt;
http://www.acadx.com</description>
      <pubDate>Thu, 20 Dec 2001 13:14:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347430#M78584</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T13:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Nested collections?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347431#M78585</link>
      <description>Here's another way to look at it from the Print Area concept (I didn't quite&lt;BR /&gt;
understand what you were looking for before)...&lt;BR /&gt;
&lt;BR /&gt;
....Set ExcelSheet = Excel.ActiveWorkbook.Sheets("Sheet1")&lt;BR /&gt;
&lt;BR /&gt;
  Dim theList As New Collection&lt;BR /&gt;
  Dim theEList As New Collection&lt;BR /&gt;
  Dim theArea, theRange&lt;BR /&gt;
  Dim i, j, c, r&lt;BR /&gt;
&lt;BR /&gt;
  theArea = ExcelSheet.PageSetup.PrintArea&lt;BR /&gt;
  r = Range(theArea).Columns.Count&lt;BR /&gt;
  Set theRange = ExcelSheet.Range(theArea)&lt;BR /&gt;
&lt;BR /&gt;
  i = 1&lt;BR /&gt;
  j = 1&lt;BR /&gt;
  For Each c In theRange.Cells&lt;BR /&gt;
    theList.Add c.Value&lt;BR /&gt;
    If j = r Then&lt;BR /&gt;
      theEList.Add theList, Str(i)&lt;BR /&gt;
      Set theList = Nothing&lt;BR /&gt;
      j = 0&lt;BR /&gt;
      i = i + 1&lt;BR /&gt;
    End If&lt;BR /&gt;
    j = j + 1&lt;BR /&gt;
  Next&lt;BR /&gt;
&lt;BR /&gt;
  If (theEList.Count &amp;gt; 0) Then&lt;BR /&gt;
    MsgBox theEList.Count &amp;amp; "-" &amp;amp; theEList(2).Item(3)&lt;BR /&gt;
  End If&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"GARYNTX" &lt;GADAMSON&gt; wrote in message&lt;BR /&gt;
news:f0a4244.-1@WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; I have a collection which contains multiple collections inside and I was&lt;BR /&gt;
wondering how to access each item of the nested collection. For example&lt;BR /&gt;
list1 would be ((1 2 3),(4 5 6)) and if I wanted to access item 4 of the&lt;BR /&gt;
second list what would be the syntax? I tried list1(2)(1) but it didn't&lt;BR /&gt;
work.&lt;BR /&gt;
&amp;gt;&lt;/GADAMSON&gt;</description>
      <pubDate>Thu, 20 Dec 2001 16:03:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/nested-collections/m-p/347431#M78585</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-12-20T16:03:36Z</dc:date>
    </item>
  </channel>
</rss>

