<?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: Sorting ListBoxes</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/</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: Yemi Adesanya</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-73483</link>
		<dc:creator>Yemi Adesanya</dc:creator>
		<pubDate>Wed, 08 Feb 2012 12:03:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-73483</guid>
		<description>Great, helpful code!
I used it for my combo boxes, at first I got a type mismatc error #13, changing &quot;MSForms.ListBox&quot; to &quot;MSForms.ComboBox&quot; solved the problem.

Also had a problem with  the &quot;-1&quot; at the end of line &quot;For i = LBound(vaItems, 1) To UBound(vaItems, 1) – 1&quot;, remove the -1 and the code is perfect.

Thank you very much!</description>
		<content:encoded><![CDATA[<p>Great, helpful code!<br />
I used it for my combo boxes, at first I got a type mismatc error #13, changing &#8220;MSForms.ListBox&#8221; to &#8220;MSForms.ComboBox&#8221; solved the problem.</p>
<p>Also had a problem with  the &#8220;-1&#8243; at the end of line &#8220;For i = LBound(vaItems, 1) To UBound(vaItems, 1) – 1&#8243;, remove the -1 and the code is perfect.</p>
<p>Thank you very much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stu</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-39891</link>
		<dc:creator>Stu</dc:creator>
		<pubDate>Tue, 16 Jun 2009 20:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-39891</guid>
		<description>&lt;p&gt;Thx! Good code, worked for me on the first try!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thx! Good code, worked for me on the first try!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans Schraven</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-33596</link>
		<dc:creator>Hans Schraven</dc:creator>
		<pubDate>Mon, 14 Jul 2008 09:12:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-33596</guid>
		<description>&lt;p&gt;My sorting solution&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; A_sortlistbox(oLb &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; ComboBox)&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;With&lt;/span&gt; Sheets(1).Range(Cells(1, 100), Cells(oLb.ListCount, 100 + oLb.ColumnCount))&lt;br&gt;
&#160; &#160; .Value = oLb.List&lt;br&gt;
&#160; &#160; .Sort .Cells(1, 1)&lt;br&gt;
&#160; &#160; sq = .Value&lt;br&gt;
&#160; &#160; oLb.List = sq&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;With&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>My sorting solution</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Sub</span> A_sortlistbox(oLb <span class="kw1">As</span> ComboBox)<br />
&nbsp; <span class="kw1">With</span> Sheets(1).Range(Cells(1, 100), Cells(oLb.ListCount, 100 + oLb.ColumnCount))<br />
&nbsp; &nbsp; .Value = oLb.List<br />
&nbsp; &nbsp; .Sort .Cells(1, 1)<br />
&nbsp; &nbsp; sq = .Value<br />
&nbsp; &nbsp; oLb.List = sq<br />
&nbsp; <span class="kw1">End</span> <span class="kw1">With</span><br />
<span class="kw1">End</span> <span class="kw1">Sub</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans Schraven</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-33564</link>
		<dc:creator>Hans Schraven</dc:creator>
		<pubDate>Sat, 12 Jul 2008 16:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-33564</guid>
		<description>&lt;p&gt;Why using&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&#160;&lt;span class=&quot;co1&quot;&gt;&#039;Clear the listbox&lt;br&gt;
&lt;/span&gt; oLb.Clear&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160;&lt;span class=&quot;co1&quot;&gt;&#039;Add the sorted array back to the listbox&lt;br&gt;
&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; i = &lt;span class=&quot;kw1&quot;&gt;LBound&lt;/span&gt;(vaItems, 1) &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;UBound&lt;/span&gt;(vaItems, 1)&lt;br&gt;
&#160; &#160;oLb.AddItem vaItems(i, 0)&lt;br&gt;
&#160;&lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt; i&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Instead of&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&#160; oLb.Clear&lt;br&gt;
&#160; oLb.List=vaItems&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>Why using</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer">&nbsp;<span class="co1">&#8216;Clear the listbox<br />
</span> oLb.Clear<br />
&nbsp; &nbsp; <br />
&nbsp;<span class="co1">&#8216;Add the sorted array back to the listbox<br />
</span> <span class="kw1">For</span> i = <span class="kw1">LBound</span>(vaItems, 1) <span class="kw1">To</span> <span class="kw1">UBound</span>(vaItems, 1)<br />
&nbsp; &nbsp;oLb.AddItem vaItems(i, 0)<br />
&nbsp;<span class="kw1">Next</span> i</div>
</div>
<p>Instead of</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer">&nbsp; oLb.Clear<br />
&nbsp; oLb.List=vaItems</div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: JerryB</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-33548</link>
		<dc:creator>JerryB</dc:creator>
		<pubDate>Fri, 11 Jul 2008 21:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-33548</guid>
		<description>&lt;p&gt;I tried the code as-is (copied to my 2007 workbook VBA) and couldn&#039;t figure out what was wrong with it until I noticed that the comments in the code were causing errors.  I had noticed that they were highlighted (error-red) and thought the highlight was due to displaying the comments.  After I reversed the quote marks the code worked just fine.&lt;/p&gt;
&lt;p&gt;I&#039;m pointing this out in case somebody else overlooked the comments like I did.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I tried the code as-is (copied to my 2007 workbook VBA) and couldn&#8217;t figure out what was wrong with it until I noticed that the comments in the code were causing errors.  I had noticed that they were highlighted (error-red) and thought the highlight was due to displaying the comments.  After I reversed the quote marks the code worked just fine.</p>
<p>I&#8217;m pointing this out in case somebody else overlooked the comments like I did.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: techphets</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-32644</link>
		<dc:creator>techphets</dc:creator>
		<pubDate>Mon, 02 Jun 2008 19:12:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-32644</guid>
		<description>&lt;p&gt;Please moderate this comment instead... &lt;/p&gt;
&lt;p&gt;I had the same problem as Aaron- &quot;object required.&quot;  I was confused about Julian&#039;s comment- make sure WHAT is MSForms.ListBox?  I copy and pasted the code and assume he was talking about the function argument. &lt;/p&gt;
&lt;p&gt;My problem was from using parenthesis to call the function: &lt;/p&gt;
&lt;p&gt;WRONG: SortListBox(MyForm.MyListBox)&lt;br&gt;
RIGHT: SortListBox MyForm.MyListBox&lt;/p&gt;
&lt;p&gt;Apparently this is a VBA quirk that I have not encountered in the past. &lt;/p&gt;
&lt;p&gt;Thanks for the script.  Even with the time spent troubleshooting I&#039;m sure it saved me an hour or so.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Please moderate this comment instead&#8230; </p>
<p>I had the same problem as Aaron- &#8220;object required.&#8221;  I was confused about Julian&#8217;s comment- make sure WHAT is MSForms.ListBox?  I copy and pasted the code and assume he was talking about the function argument. </p>
<p>My problem was from using parenthesis to call the function: </p>
<p>WRONG: SortListBox(MyForm.MyListBox)<br />
RIGHT: SortListBox MyForm.MyListBox</p>
<p>Apparently this is a VBA quirk that I have not encountered in the past. </p>
<p>Thanks for the script.  Even with the time spent troubleshooting I&#8217;m sure it saved me an hour or so.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-21633</link>
		<dc:creator>Jan</dc:creator>
		<pubDate>Tue, 28 Nov 2006 18:20:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-21633</guid>
		<description>&lt;p&gt;To add to this just in case anyone is interested there is a way to get round the ridiculous 11 columns nonsense.  Use arrays !  setup Listbox data in an array and then the list box will behave it self.  To be honest I cannot believe that these list boxes have been dragged kicking and screaming from excel 97 through to 2003 with little or no changes.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>To add to this just in case anyone is interested there is a way to get round the ridiculous 11 columns nonsense.  Use arrays !  setup Listbox data in an array and then the list box will behave it self.  To be honest I cannot believe that these list boxes have been dragged kicking and screaming from excel 97 through to 2003 with little or no changes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-21628</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Mon, 27 Nov 2006 23:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-21628</guid>
		<description>&lt;p&gt;For the benefit of Thomas or anyone in a similar situation:&lt;/p&gt;
&lt;p&gt;Note that Listboxes treat their items as character strings, so the comparison as written above:&lt;br&gt;
vaItems(i, 0) &gt; vaItems(j, 0)&lt;br&gt;
is a string comparison. Even if you put in numbers when you call Listbox.Add(), the Listbox will convert them to strings for storing internally, and so will give you back an array of strings when you call Listbox.List() (and that array is what is getting sorted).&lt;/p&gt;
&lt;p&gt;To sort the data in numerical order, you need to make numeric comparisons, so you need to convert the items in the array to numbers (such as integers) before comparing them, something like:&lt;br&gt;
CInt(vaItems(i, 0)) &gt; CInt(vaItems(j, 0))&lt;/p&gt;
&lt;p&gt;However, you should choose the appropriate conversion function for your data. If you are sure your data are relatively small integers (less than 2 billion), CInt() will suffice, but very large numbers will require CLng(), and numbers that have decimal components will require CDec() (for exact decimal comparison) or CDbl() (for approximate decimal comparison).&lt;/p&gt;
&lt;p&gt;After the comparison, it&#039;s not necessary to treat the data as numbers anymore, so the rest of the code remains the same.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>For the benefit of Thomas or anyone in a similar situation:</p>
<p>Note that Listboxes treat their items as character strings, so the comparison as written above:<br />
vaItems(i, 0) &gt; vaItems(j, 0)<br />
is a string comparison. Even if you put in numbers when you call Listbox.Add(), the Listbox will convert them to strings for storing internally, and so will give you back an array of strings when you call Listbox.List() (and that array is what is getting sorted).</p>
<p>To sort the data in numerical order, you need to make numeric comparisons, so you need to convert the items in the array to numbers (such as integers) before comparing them, something like:<br />
CInt(vaItems(i, 0)) &gt; CInt(vaItems(j, 0))</p>
<p>However, you should choose the appropriate conversion function for your data. If you are sure your data are relatively small integers (less than 2 billion), CInt() will suffice, but very large numbers will require CLng(), and numbers that have decimal components will require CDec() (for exact decimal comparison) or CDbl() (for approximate decimal comparison).</p>
<p>After the comparison, it&#8217;s not necessary to treat the data as numbers anymore, so the rest of the code remains the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julian</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-21520</link>
		<dc:creator>Julian</dc:creator>
		<pubDate>Thu, 09 Nov 2006 01:55:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-21520</guid>
		<description>&lt;p&gt;Aaron, make sure it&#039;s - &quot;MSForms.ListBox&quot;.  It took me 2hrs to fix it.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Aaron, make sure it&#8217;s &#8211; &#8220;MSForms.ListBox&#8221;.  It took me 2hrs to fix it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Dyck</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/05/12/sorting-listboxes/#comment-21423</link>
		<dc:creator>Aaron Dyck</dc:creator>
		<pubDate>Tue, 31 Oct 2006 04:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=539#comment-21423</guid>
		<description>&lt;p&gt;I can&#039;t figure out how to pass my listbox to the routine - it always comes back at me and says &#039;object required&#039;.  Am I doing something wrong?  I enter SortListBox(lbxname) and it doesn&#039;t seem to like my arguments.  Suggestions?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I can&#8217;t figure out how to pass my listbox to the routine &#8211; it always comes back at me and says &#8216;object required&#8217;.  Am I doing something wrong?  I enter SortListBox(lbxname) and it doesn&#8217;t seem to like my arguments.  Suggestions?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

