<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Sort a Collection</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2004/06/02/sort-a-collection/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2004/06/02/sort-a-collection/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:28:40 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Chris</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/02/sort-a-collection/#comment-17697</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 09 Dec 2005 12:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=595#comment-17697</guid>
		<description>&lt;p&gt;Hi, &lt;/p&gt;
&lt;p&gt;it isn&#039;t possible to get the keys of a collections. You can only check if a key exsists (http://www.vb-tec.de/collctns.htm text is german, but sourcecode is in english). So, if you know all keys of the collection you are lucky.&lt;br&gt;
What about this sub:&lt;/p&gt;
&lt;p&gt;Sub sortCollection(Data As Collection, Optional Keys = False)&lt;/p&gt;
&lt;p&gt;Dim vItm As Variant&lt;br&gt;
Dim i As Long, j As Long&lt;br&gt;
Dim vTemp As Variant&lt;/p&gt;
&lt;p&gt;If Keys = True Then&lt;br&gt;
    For i = 1 To Data.Count - 1&lt;br&gt;
      For j = i + 1 To Data.Count&lt;br&gt;
        If Data(i) &gt; Data(j) Then&lt;br&gt;
            &#039;store the lesser item&lt;br&gt;
            vTemp = Data(j)&lt;br&gt;
            &#039;remove the lesser item&lt;br&gt;
            Data.Remove j&lt;br&gt;
            &#039;re-add the lesser item before the&lt;br&gt;
            &#039;greater Item&lt;br&gt;
            Data.Add vTemp, vTemp, i&lt;br&gt;
        End If&lt;br&gt;
      Next j&lt;br&gt;
    Next i&lt;br&gt;
Else&lt;br&gt;
    For i = 1 To Data.Count - 1&lt;br&gt;
      For j = i + 1 To Data.Count&lt;br&gt;
        If Data(i) &gt; Data(j) Then&lt;br&gt;
            &#039;store the lesser item&lt;br&gt;
            vTemp = Data(j)&lt;br&gt;
            &#039;remove the lesser item&lt;br&gt;
            Data.Remove j&lt;br&gt;
            &#039;re-add the lesser item before the&lt;br&gt;
            &#039;greater Item&lt;br&gt;
            Data.Add vTemp, , i&lt;br&gt;
        End If&lt;br&gt;
      Next j&lt;br&gt;
    Next i&lt;br&gt;
End If&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;It can&#039;t maintain your userdef keys, but can sort both collections: collections with keys same as values and collections without keys. If you pass a collection with userdef. keys you will get a collection whitch has keys and values the same...&lt;br&gt;
Thank you for this small code, i find it very useful.&lt;/p&gt;
&lt;p&gt;greetings,&lt;br&gt;
Chris&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>it isn&#8217;t possible to get the keys of a collections. You can only check if a key exsists (<a href="http://www.vb-tec.de/collctns.htm" rel="nofollow">http://www.vb-tec.de/collctns.htm</a> text is german, but sourcecode is in english). So, if you know all keys of the collection you are lucky.<br />
What about this sub:</p>
<p>Sub sortCollection(Data As Collection, Optional Keys = False)</p>
<p>Dim vItm As Variant<br />
Dim i As Long, j As Long<br />
Dim vTemp As Variant</p>
<p>If Keys = True Then<br />
    For i = 1 To Data.Count &#8211; 1<br />
      For j = i + 1 To Data.Count<br />
        If Data(i) &gt; Data(j) Then<br />
            &#8216;store the lesser item<br />
            vTemp = Data(j)<br />
            &#8216;remove the lesser item<br />
            Data.Remove j<br />
            &#8216;re-add the lesser item before the<br />
            &#8216;greater Item<br />
            Data.Add vTemp, vTemp, i<br />
        End If<br />
      Next j<br />
    Next i<br />
Else<br />
    For i = 1 To Data.Count &#8211; 1<br />
      For j = i + 1 To Data.Count<br />
        If Data(i) &gt; Data(j) Then<br />
            &#8216;store the lesser item<br />
            vTemp = Data(j)<br />
            &#8216;remove the lesser item<br />
            Data.Remove j<br />
            &#8216;re-add the lesser item before the<br />
            &#8216;greater Item<br />
            Data.Add vTemp, , i<br />
        End If<br />
      Next j<br />
    Next i<br />
End If<br />
End Sub</p>
<p>It can&#8217;t maintain your userdef keys, but can sort both collections: collections with keys same as values and collections without keys. If you pass a collection with userdef. keys you will get a collection whitch has keys and values the same&#8230;<br />
Thank you for this small code, i find it very useful.</p>
<p>greetings,<br />
Chris</p>
]]></content:encoded>
	</item>
</channel>
</rss>

