<?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: Pages to Print</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 18:06:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Rick Rothstein (MVP - Excel)</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48552</link>
		<dc:creator>Rick Rothstein (MVP - Excel)</dc:creator>
		<pubDate>Mon, 02 Aug 2010 22:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48552</guid>
		<description>&lt;p&gt;&gt;&gt; @Rick - testing for numbers at beginning and end while allowing single page&lt;br&gt;
&gt;&gt; ranges for pages 1 through 9 requires 2 tests. The &quot;#*#&quot; test fails for&lt;br&gt;
&gt;&gt; &quot;1?, &quot;2?, etc. It should fail for &quot;0?, so maybe the beginning test should be &quot;[1-9]*&quot;.&lt;/p&gt;
&lt;p&gt;Doh! I got so caught up in the range &quot;thing&quot; that I completely forgot about single non-range numbers. And yes, the leading number test should be for non-zero numbers, but in order to protect against someone entering 04-09 as a range, I made the Like test for leading numbers against Val(sInput) rather than against sInput directly (letting VB handle the behind-the-scenes conversion of the resulting number back to a String value). I also added an Else statement in my If..Then block to handle the stripping away of leading zeroes for single pages that might start with zero. And now, the final(?) code[grin]...&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;Function&lt;/span&gt; PagesToPrint(sInput &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;) &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Variant&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; X &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, Z &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, Temp &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;, sNumbers() &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;, sRange() &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*# #*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; Bad&lt;br&gt;
&#160; sInput = Replace(sInput, &lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;, &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*[!0-9,-]*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*[,-][,-]*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*#&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; Val(sInput) &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;[1-9]*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; Bad&lt;br&gt;
&#160; sNumbers = Split(sInput, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; X = 0 &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;UBound&lt;/span&gt;(sNumbers)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sNumbers(X) &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sNumbers(X) &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-*-*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; Bad&lt;br&gt;
&#160; &#160; &#160; sRange = Split(sNumbers(X), &lt;span class=&quot;st0&quot;&gt;&quot;-&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &#160; &#160; sNumbers(X) = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; Z = sRange(0) &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; sRange(1) &lt;span class=&quot;kw1&quot;&gt;Step&lt;/span&gt; Sgn(sRange(1) - sRange(0) + 0.1)&lt;br&gt;
&#160; &#160; &#160; &#160; sNumbers(X) = sNumbers(X) &amp; &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt; &amp; Z&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; sNumbers(X) = Mid(sNumbers(X), 2)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; sNumbers(X) = Val(sNumbers(X))&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160; PagesToPrint = Split(Join(sNumbers, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;), &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Exit&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;br&gt;
Bad:&lt;br&gt;
&#160; PagesToPrint = Array()&lt;br&gt;
&#160; MsgBox &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &amp; sInput &amp; &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &amp; vbLf &amp; vbLf &amp; &lt;span class=&quot;st0&quot;&gt;&quot;The range of values you specified is incorrectly formed!&quot;&lt;/span&gt;, vbCritical&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>&gt;&gt; @Rick &#8211; testing for numbers at beginning and end while allowing single page<br />
&gt;&gt; ranges for pages 1 through 9 requires 2 tests. The &#8220;#*#&#8221; test fails for<br />
&gt;&gt; &#8220;1?, &#8220;2?, etc. It should fail for &#8220;0?, so maybe the beginning test should be &#8220;[1-9]*&#8221;.</p>
<p>Doh! I got so caught up in the range &#8220;thing&#8221; that I completely forgot about single non-range numbers. And yes, the leading number test should be for non-zero numbers, but in order to protect against someone entering 04-09 as a range, I made the Like test for leading numbers against Val(sInput) rather than against sInput directly (letting VB handle the behind-the-scenes conversion of the resulting number back to a String value). I also added an Else statement in my If..Then block to handle the stripping away of leading zeroes for single pages that might start with zero. And now, the final(?) code[grin]&#8230;</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Function</span> PagesToPrint(sInput <span class="kw1">As</span> <span class="kw1">String</span>) <span class="kw1">As</span> <span class="kw1">Variant</span><br />
&nbsp; <span class="kw1">Dim</span> X <span class="kw1">As</span> <span class="kw1">Long</span>, Z <span class="kw1">As</span> <span class="kw1">Long</span>, Temp <span class="kw1">As</span> <span class="kw1">String</span>, sNumbers() <span class="kw1">As</span> <span class="kw1">String</span>, sRange() <span class="kw1">As</span> <span class="kw1">String</span><br />
&nbsp; <span class="kw1">If</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*# #*&#8221;</span> <span class="kw1">Then</span> <span class="kw1">GoTo</span> Bad<br />
&nbsp; sInput = Replace(sInput, <span class="st0">&#8221; &#8220;</span>, <span class="st0">&#8220;&#8221;</span>)<br />
&nbsp; <span class="kw1">If</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*[!0-9,-]*&#8221;</span> <span class="kw1">Or</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*[,-][,-]*&#8221;</span> <span class="kw1">Or</span> <span class="kw1">Not</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*#&#8221;</span> <span class="kw1">Or</span> <span class="kw1">Not</span> Val(sInput) <span class="kw1">Like</span> <span class="st0">&#8220;[1-9]*&#8221;</span> <span class="kw1">Then</span> <span class="kw1">GoTo</span> Bad<br />
&nbsp; sNumbers = Split(sInput, <span class="st0">&#8220;,&#8221;</span>)<br />
&nbsp; <span class="kw1">For</span> X = 0 <span class="kw1">To</span> <span class="kw1">UBound</span>(sNumbers)<br />
&nbsp; &nbsp; <span class="kw1">If</span> sNumbers(X) <span class="kw1">Like</span> <span class="st0">&#8220;*-*&#8221;</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">If</span> sNumbers(X) <span class="kw1">Like</span> <span class="st0">&#8220;*-*-*&#8221;</span> <span class="kw1">Then</span> <span class="kw1">GoTo</span> Bad<br />
&nbsp; &nbsp; &nbsp; sRange = Split(sNumbers(X), <span class="st0">&#8220;-&#8221;</span>)<br />
&nbsp; &nbsp; &nbsp; sNumbers(X) = <span class="st0">&#8220;&#8221;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">For</span> Z = sRange(0) <span class="kw1">To</span> sRange(1) <span class="kw1">Step</span> Sgn(sRange(1) &#8211; sRange(0) + 0.1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; sNumbers(X) = sNumbers(X) &amp; <span class="st0">&#8220;,&#8221;</span> &amp; Z<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">Next</span><br />
&nbsp; &nbsp; &nbsp; sNumbers(X) = Mid(sNumbers(X), 2)<br />
&nbsp; &nbsp; <span class="kw1">Else</span><br />
&nbsp; &nbsp; &nbsp; sNumbers(X) = Val(sNumbers(X))<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; <span class="kw1">Next</span><br />
&nbsp; PagesToPrint = Split(Join(sNumbers, <span class="st0">&#8220;,&#8221;</span>), <span class="st0">&#8220;,&#8221;</span>)<br />
&nbsp; <span class="kw1">Exit</span> <span class="kw1">Function</span><br />
Bad:<br />
&nbsp; PagesToPrint = Array()<br />
&nbsp; MsgBox <span class="st0">&#8220;&#8221;</span><span class="st0">&#8220;&#8221;</span> &amp; sInput &amp; <span class="st0">&#8220;&#8221;</span><span class="st0">&#8220;&#8221;</span> &amp; vbLf &amp; vbLf &amp; <span class="st0">&#8220;The range of values you specified is incorrectly formed!&#8221;</span>, vbCritical<br />
<span class="kw1">End</span> <span class="kw1">Function</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48543</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Mon, 02 Aug 2010 18:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48543</guid>
		<description>&lt;p&gt;@Rick - testing for numbers at beginning and end &lt;b&gt;while allowing single page ranges for pages 1 through 9&lt;/b&gt; requires &lt;b&gt;2&lt;/b&gt; tests. The &quot;#*#&quot; test fails for &quot;1?, &quot;2?, etc. It should fail for &quot;0?, so maybe the beginning test should be &quot;[1-9]*&quot;.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Rick &#8211; testing for numbers at beginning and end <b>while allowing single page ranges for pages 1 through 9</b> requires <b>2</b> tests. The &#8220;#*#&#8221; test fails for &#8220;1?, &#8220;2?, etc. It should fail for &#8220;0?, so maybe the beginning test should be &#8220;[1-9]*&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Rothstein (MVP - Excel)</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48522</link>
		<dc:creator>Rick Rothstein (MVP - Excel)</dc:creator>
		<pubDate>Sun, 01 Aug 2010 04:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48522</guid>
		<description>&lt;p&gt;&gt;&gt; Other than NIH, any good reason to use the 4 patterns &quot;*,-*&quot;, &quot;*-,*&quot;, &quot;*,,*&quot;&lt;br&gt;
&gt;&gt; and &quot;**&quot; rather than the 1 pattern &quot;*[,-][,-]*&quot;&lt;/p&gt;
&lt;p&gt;Nope, just simple inattention on my part.&lt;/p&gt;
&lt;p&gt;&gt;&gt; or the 4 patters &quot;-&quot;, &quot;,&quot;, &quot;,*&quot; and &quot;*,&quot; (shouldn&#039;t there be 6 patterns&lt;br&gt;
&gt;&gt; including &quot;*-&quot; and &quot;-*&quot;?) rather than the 2 patterns &quot;#*&quot; and &quot;*#&quot;?&lt;/p&gt;
&lt;p&gt;Same excuse, although you missed a simplification yourself... only one pattern test is needed... &quot;#*#&quot;&lt;/p&gt;
&lt;p&gt;&gt;&gt; Fair point about spaces between numerals. They should be errors. But that makes the validation rules just&lt;br&gt;
&gt;&gt; - no spaces between numerals, and after this check all spaces may be removed at which point&lt;br&gt;
&gt;&gt; - no chars other than numerals, commas and hyphens&lt;br&gt;
&gt;&gt; - no chars other than numerals in first and last positions&lt;br&gt;
&gt;&gt; - no sequences of 2 or more non-numerals&lt;br&gt;
&gt;&gt; - no more than 1 hyphen between commas&lt;/p&gt;
&lt;p&gt;Charting it like this before starting to write any code (instead of writing code as I thought of each condition) is definitely the much, much better way to approach this problem... the code to handle the conditions when laid out like this is much easier to see. Because you can&#039;t make Like searches &quot;ungreedy&quot;, the last item in the list has to be handled the way I currently do it... inside the loop after sInput is Split apart. Before finishing up, I just wanted to thank you for slapping-me-upside-of-my-head with all this, it was much appreciated. Okay, so here is the modified (and I think final[grin]) code for my approach to the original problem...&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;Function&lt;/span&gt; PagesToPrint(sInput &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;) &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Variant&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; X &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, Z &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, Temp &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;, sNumbers() &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;, sRange() &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*# #*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; Bad&lt;br&gt;
&#160; sInput = Replace(sInput, &lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;, &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*[!0-9,-]*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*[,-][,-]*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;#*#&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; Bad&lt;br&gt;
&#160; sNumbers = Split(sInput, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; X = 0 &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;UBound&lt;/span&gt;(sNumbers)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sNumbers(X) &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sNumbers(X) &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-*-*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; Bad&lt;br&gt;
&#160; &#160; &#160; sRange = Split(sNumbers(X), &lt;span class=&quot;st0&quot;&gt;&quot;-&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &#160; &#160; sNumbers(X) = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; Z = sRange(0) &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; sRange(1) &lt;span class=&quot;kw1&quot;&gt;Step&lt;/span&gt; Sgn(sRange(1) - sRange(0) + 0.1)&lt;br&gt;
&#160; &#160; &#160; &#160; sNumbers(X) = sNumbers(X) &amp; &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt; &amp; Z&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; sNumbers(X) = Mid(sNumbers(X), 2)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160; PagesToPrint = Split(Join(sNumbers, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;), &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Exit&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;br&gt;
Bad:&lt;br&gt;
&#160; PagesToPrint = Array()&lt;br&gt;
&#160; MsgBox &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &amp; sInput &amp; &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &amp; vbLf &amp; vbLf &amp; &lt;span class=&quot;st0&quot;&gt;&quot;The range of values you specified is incorrectly formed!&quot;&lt;/span&gt;, vbCritical&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>&gt;&gt; Other than NIH, any good reason to use the 4 patterns &#8220;*,-*&#8221;, &#8220;*-,*&#8221;, &#8220;*,,*&#8221;<br />
&gt;&gt; and &#8220;**&#8221; rather than the 1 pattern &#8220;*[,-][,-]*&#8221;</p>
<p>Nope, just simple inattention on my part.</p>
<p>&gt;&gt; or the 4 patters &#8220;-&#8221;, &#8220;,&#8221;, &#8220;,*&#8221; and &#8220;*,&#8221; (shouldn&#8217;t there be 6 patterns<br />
&gt;&gt; including &#8220;*-&#8221; and &#8220;-*&#8221;?) rather than the 2 patterns &#8220;#*&#8221; and &#8220;*#&#8221;?</p>
<p>Same excuse, although you missed a simplification yourself&#8230; only one pattern test is needed&#8230; &#8220;#*#&#8221;</p>
<p>&gt;&gt; Fair point about spaces between numerals. They should be errors. But that makes the validation rules just<br />
&gt;&gt; &#8211; no spaces between numerals, and after this check all spaces may be removed at which point<br />
&gt;&gt; &#8211; no chars other than numerals, commas and hyphens<br />
&gt;&gt; &#8211; no chars other than numerals in first and last positions<br />
&gt;&gt; &#8211; no sequences of 2 or more non-numerals<br />
&gt;&gt; &#8211; no more than 1 hyphen between commas</p>
<p>Charting it like this before starting to write any code (instead of writing code as I thought of each condition) is definitely the much, much better way to approach this problem&#8230; the code to handle the conditions when laid out like this is much easier to see. Because you can&#8217;t make Like searches &#8220;ungreedy&#8221;, the last item in the list has to be handled the way I currently do it&#8230; inside the loop after sInput is Split apart. Before finishing up, I just wanted to thank you for slapping-me-upside-of-my-head with all this, it was much appreciated. Okay, so here is the modified (and I think final[grin]) code for my approach to the original problem&#8230;</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Function</span> PagesToPrint(sInput <span class="kw1">As</span> <span class="kw1">String</span>) <span class="kw1">As</span> <span class="kw1">Variant</span><br />
&nbsp; <span class="kw1">Dim</span> X <span class="kw1">As</span> <span class="kw1">Long</span>, Z <span class="kw1">As</span> <span class="kw1">Long</span>, Temp <span class="kw1">As</span> <span class="kw1">String</span>, sNumbers() <span class="kw1">As</span> <span class="kw1">String</span>, sRange() <span class="kw1">As</span> <span class="kw1">String</span><br />
&nbsp; <span class="kw1">If</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*# #*&#8221;</span> <span class="kw1">Then</span> <span class="kw1">GoTo</span> Bad<br />
&nbsp; sInput = Replace(sInput, <span class="st0">&#8221; &#8220;</span>, <span class="st0">&#8220;&#8221;</span>)<br />
&nbsp; <span class="kw1">If</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*[!0-9,-]*&#8221;</span> <span class="kw1">Or</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*[,-][,-]*&#8221;</span> <span class="kw1">Or</span> <span class="kw1">Not</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;#*#&#8221;</span> <span class="kw1">Then</span> <span class="kw1">GoTo</span> Bad<br />
&nbsp; sNumbers = Split(sInput, <span class="st0">&#8220;,&#8221;</span>)<br />
&nbsp; <span class="kw1">For</span> X = 0 <span class="kw1">To</span> <span class="kw1">UBound</span>(sNumbers)<br />
&nbsp; &nbsp; <span class="kw1">If</span> sNumbers(X) <span class="kw1">Like</span> <span class="st0">&#8220;*-*&#8221;</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">If</span> sNumbers(X) <span class="kw1">Like</span> <span class="st0">&#8220;*-*-*&#8221;</span> <span class="kw1">Then</span> <span class="kw1">GoTo</span> Bad<br />
&nbsp; &nbsp; &nbsp; sRange = Split(sNumbers(X), <span class="st0">&#8220;-&#8221;</span>)<br />
&nbsp; &nbsp; &nbsp; sNumbers(X) = <span class="st0">&#8220;&#8221;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">For</span> Z = sRange(0) <span class="kw1">To</span> sRange(1) <span class="kw1">Step</span> Sgn(sRange(1) &#8211; sRange(0) + 0.1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; sNumbers(X) = sNumbers(X) &amp; <span class="st0">&#8220;,&#8221;</span> &amp; Z<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">Next</span><br />
&nbsp; &nbsp; &nbsp; sNumbers(X) = Mid(sNumbers(X), 2)<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; <span class="kw1">Next</span><br />
&nbsp; PagesToPrint = Split(Join(sNumbers, <span class="st0">&#8220;,&#8221;</span>), <span class="st0">&#8220;,&#8221;</span>)<br />
&nbsp; <span class="kw1">Exit</span> <span class="kw1">Function</span><br />
Bad:<br />
&nbsp; PagesToPrint = Array()<br />
&nbsp; MsgBox <span class="st0">&#8220;&#8221;</span><span class="st0">&#8220;&#8221;</span> &amp; sInput &amp; <span class="st0">&#8220;&#8221;</span><span class="st0">&#8220;&#8221;</span> &amp; vbLf &amp; vbLf &amp; <span class="st0">&#8220;The range of values you specified is incorrectly formed!&#8221;</span>, vbCritical<br />
<span class="kw1">End</span> <span class="kw1">Function</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48521</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Sun, 01 Aug 2010 02:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48521</guid>
		<description>&lt;p&gt;Other than NIH, any &lt;b&gt;good&lt;/b&gt; reason to use the 4 patterns &quot;*,-*&quot;, &quot;*-,*&quot;, &quot;*,,*&quot; and &quot;**&quot; rather than the &lt;b&gt;1&lt;/b&gt; pattern &quot;*[,-][,-]*&quot; or the 4 patters &quot;-&quot;, &quot;,&quot;, &quot;,*&quot; and &quot;*,&quot; (shouldn&#039;t there be 6 patterns including &quot;*-&quot; and &quot;-*&quot;?) rather than the &lt;b&gt;2&lt;/b&gt; patterns &quot;#*&quot; and &quot;*#&quot;?&lt;/p&gt;
&lt;p&gt;Fair point about spaces between numerals. They should be errors. But that makes the validation rules just&lt;br&gt;
- no spaces between numerals, and after this check all spaces may be removed at which point&lt;br&gt;
- no chars other than numerals, commas and hyphens&lt;br&gt;
- no chars other than numerals in first and last positions&lt;br&gt;
- no sequences of 2 or more non-numerals&lt;br&gt;
- no more than 1 hyphen between commas&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Other than NIH, any <b>good</b> reason to use the 4 patterns &#8220;*,-*&#8221;, &#8220;*-,*&#8221;, &#8220;*,,*&#8221; and &#8220;**&#8221; rather than the <b>1</b> pattern &#8220;*[,-][,-]*&#8221; or the 4 patters &#8220;-&#8221;, &#8220;,&#8221;, &#8220;,*&#8221; and &#8220;*,&#8221; (shouldn&#8217;t there be 6 patterns including &#8220;*-&#8221; and &#8220;-*&#8221;?) rather than the <b>2</b> patterns &#8220;#*&#8221; and &#8220;*#&#8221;?</p>
<p>Fair point about spaces between numerals. They should be errors. But that makes the validation rules just<br />
- no spaces between numerals, and after this check all spaces may be removed at which point<br />
- no chars other than numerals, commas and hyphens<br />
- no chars other than numerals in first and last positions<br />
- no sequences of 2 or more non-numerals<br />
- no more than 1 hyphen between commas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Rothstein (MVP - Excel)</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48519</link>
		<dc:creator>Rick Rothstein (MVP - Excel)</dc:creator>
		<pubDate>Sat, 31 Jul 2010 22:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48519</guid>
		<description>&lt;p&gt;@fzz,&lt;/p&gt;
&lt;p&gt;Okay, I corrected the leading trailing problem that you pointed out and I also modified the code to allow blank spaces everywhere except between digits and I also modified the code to allow hyphenated ranges in reverse order (the reverse ordering is preserved when the values are assigned into the returned array from the function)...&lt;/p&gt;
&lt;p&gt;Function PagesToPrint(sInput As String) As Variant&lt;br&gt;
  Dim X As Long, Z As Long, Temp As String, sNumbers() As String, sRange() As String&lt;br&gt;
  If sInput Like &quot;*# #*&quot; Then GoTo Bad&lt;br&gt;
  sInput = Replace(sInput, &quot; &quot;, &quot;&quot;)&lt;br&gt;
  If sInput Like &quot;*[!0-9,-]*&quot; Or sInput Like &quot;*,-*&quot; Or sInput Like &quot;*-,*&quot; Or _&lt;br&gt;
         sInput Like &quot;*,,*&quot; Or sInput Like &quot;**&quot; Or sInput Like &quot;-&quot; Or _&lt;br&gt;
         sInput Like &quot;,&quot; Or sInput Like &quot;,*&quot; Or sInput Like &quot;*,&quot; Then GoTo Bad&lt;br&gt;
  sNumbers = Split(sInput, &quot;,&quot;)&lt;br&gt;
  For X = 0 To UBound(sNumbers)&lt;br&gt;
    If sNumbers(X) Like &quot;*-*&quot; Then&lt;br&gt;
      If sNumbers(X) Like &quot;*-*-*&quot; Then GoTo Bad&lt;br&gt;
      sRange = Split(sNumbers(X), &quot;-&quot;)&lt;br&gt;
      sNumbers(X) = &quot;&quot;&lt;br&gt;
      For Z = sRange(0) To sRange(1) Step Sgn(sRange(1) - sRange(0) + 0.1)&lt;br&gt;
        sNumbers(X) = sNumbers(X) &amp; &quot;,&quot; &amp; Z&lt;br&gt;
      Next&lt;br&gt;
      sNumbers(X) = Mid(sNumbers(X), 2)&lt;br&gt;
    End If&lt;br&gt;
  Next&lt;br&gt;
  PagesToPrint = Split(Join(sNumbers, &quot;,&quot;), &quot;,&quot;)&lt;br&gt;
  Exit Function&lt;br&gt;
Bad:&lt;br&gt;
  PagesToPrint = Array()&lt;br&gt;
  MsgBox &quot;&quot;&quot;&quot; &amp; sInput &amp; &quot;&quot;&quot;&quot; &amp; vbLf &amp; vbLf &amp; &quot;The range of values you specified is incorrectly formed!&quot;, vbCritical&lt;br&gt;
End Function&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@fzz,</p>
<p>Okay, I corrected the leading trailing problem that you pointed out and I also modified the code to allow blank spaces everywhere except between digits and I also modified the code to allow hyphenated ranges in reverse order (the reverse ordering is preserved when the values are assigned into the returned array from the function)&#8230;</p>
<p>Function PagesToPrint(sInput As String) As Variant<br />
  Dim X As Long, Z As Long, Temp As String, sNumbers() As String, sRange() As String<br />
  If sInput Like &#8220;*# #*&#8221; Then GoTo Bad<br />
  sInput = Replace(sInput, &#8221; &#8220;, &#8220;&#8221;)<br />
  If sInput Like &#8220;*[!0-9,-]*&#8221; Or sInput Like &#8220;*,-*&#8221; Or sInput Like &#8220;*-,*&#8221; Or _<br />
         sInput Like &#8220;*,,*&#8221; Or sInput Like &#8220;**&#8221; Or sInput Like &#8220;-&#8221; Or _<br />
         sInput Like &#8220;,&#8221; Or sInput Like &#8220;,*&#8221; Or sInput Like &#8220;*,&#8221; Then GoTo Bad<br />
  sNumbers = Split(sInput, &#8220;,&#8221;)<br />
  For X = 0 To UBound(sNumbers)<br />
    If sNumbers(X) Like &#8220;*-*&#8221; Then<br />
      If sNumbers(X) Like &#8220;*-*-*&#8221; Then GoTo Bad<br />
      sRange = Split(sNumbers(X), &#8220;-&#8221;)<br />
      sNumbers(X) = &#8220;&#8221;<br />
      For Z = sRange(0) To sRange(1) Step Sgn(sRange(1) &#8211; sRange(0) + 0.1)<br />
        sNumbers(X) = sNumbers(X) &amp; &#8220;,&#8221; &amp; Z<br />
      Next<br />
      sNumbers(X) = Mid(sNumbers(X), 2)<br />
    End If<br />
  Next<br />
  PagesToPrint = Split(Join(sNumbers, &#8220;,&#8221;), &#8220;,&#8221;)<br />
  Exit Function<br />
Bad:<br />
  PagesToPrint = Array()<br />
  MsgBox &#8220;&#8221;"&#8221; &amp; sInput &amp; &#8220;&#8221;"&#8221; &amp; vbLf &amp; vbLf &amp; &#8220;The range of values you specified is incorrectly formed!&#8221;, vbCritical<br />
End Function</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48484</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Fri, 30 Jul 2010 19:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48484</guid>
		<description>&lt;p&gt;OK, one screw-up. Can&#039;t use a Like pattern to test exhaustively for multiple hyphens between commas, but my test should be expanded as follows.&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;br&gt;
&#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-[0-9]-*&quot;&lt;/span&gt; _&lt;br&gt;
&#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-[0-9][0-9]-*&quot;&lt;/span&gt; _&lt;br&gt;
&#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-[0-9][0-9][0-9]-*&quot;&lt;/span&gt; _&lt;br&gt;
&#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-[0-9][0-9][0-9][0-9]-*&quot;&lt;/span&gt; _&lt;br&gt;
&#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-[0-9][0-9][0-9][0-9][0-9]-*&quot;&lt;/span&gt; _&lt;br&gt;
&#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-[0-9][0-9][0-9][0-9][0-9][0-9]-*&quot;&lt;/span&gt; _&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; ps = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;One more reason to prefer regular expressions.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>OK, one screw-up. Can&#8217;t use a Like pattern to test exhaustively for multiple hyphens between commas, but my test should be expanded as follows.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer">&#8230;<br />
&nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*-[0-9]-*&#8221;</span> _<br />
&nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*-[0-9][0-9]-*&#8221;</span> _<br />
&nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*-[0-9][0-9][0-9]-*&#8221;</span> _<br />
&nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*-[0-9][0-9][0-9][0-9]-*&#8221;</span> _<br />
&nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*-[0-9][0-9][0-9][0-9][0-9]-*&#8221;</span> _<br />
&nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*-[0-9][0-9][0-9][0-9][0-9][0-9]-*&#8221;</span> _<br />
&nbsp; <span class="kw1">Then</span> ps = <span class="st0">&#8220;&#8221;</span></div>
</div>
<p>One more reason to prefer regular expressions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48483</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Fri, 30 Jul 2010 19:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48483</guid>
		<description>&lt;p&gt;@Rick - regular expressions have been discussed before in this blog, and the blog is meant for more sophisticated users and developers, you know, those who aren&#039;t afraid to do a bit of self-study.&lt;/p&gt;
&lt;p&gt;You still have errors. Pass your latest function &quot;1,2,&quot; and it returns {&quot;1?,&quot;2?,&quot;&quot;}. Your validity checking fails when SInput begins or ends with a comma.&lt;/p&gt;
&lt;p&gt;If you really insist on using Like patterns, then at least use them optimally.&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;Function&lt;/span&gt; foobar(ps &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;) &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Variant&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; i &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, j &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, k &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, n &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, p &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, t &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; ps = Replace(ps, &lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;, &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;) &#160;&lt;span class=&quot;co1&quot;&gt;&#039;why not allow whitespace like Word does?&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*[!0-9,-]*&quot;&lt;/span&gt; _&lt;br&gt;
&#160; &#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;[!0-9]*&quot;&lt;/span&gt; _&lt;br&gt;
&#160; &#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*[!0-9]&quot;&lt;/span&gt; _&lt;br&gt;
&#160; &#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*[,-][,-]*&quot;&lt;/span&gt; _&lt;br&gt;
&#160; &#160;&lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; ps &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-[0-9]-*&quot;&lt;/span&gt; _&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; ps = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; p = InStrRev(ps, &lt;span class=&quot;st0&quot;&gt;&quot;-&quot;&lt;/span&gt;) &#160;&lt;span class=&quot;co1&quot;&gt;&#039;right to left!!&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Do&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;While&lt;/span&gt; p &gt; 0&lt;br&gt;
&#160; &#160; i = InStrRev(ps, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;, p - 1) + 1&lt;br&gt;
&#160; &#160; j = &lt;span class=&quot;kw1&quot;&gt;CLng&lt;/span&gt;(Mid$(ps, i, p - i))&lt;br&gt;
&#160; &#160; i = InStr(p + 1, ps, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;) - 1&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; i = -1 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; k = &lt;span class=&quot;kw1&quot;&gt;CLng&lt;/span&gt;(Mid$(ps, p + 1)) &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt; k = &lt;span class=&quot;kw1&quot;&gt;CLng&lt;/span&gt;(Mid$(ps, p + 1, i - p))&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; j = k &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &#160;&lt;span class=&quot;co1&quot;&gt;&#039;allow trivial ranges like 3-3, but not much to do&lt;br&gt;
&lt;/span&gt; &#160; &#160; &#160;ps = Left$(ps, p - 1) &amp; Mid$(ps, i + 1)&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; n = Sgn(k - j) &#160;&lt;span class=&quot;co1&quot;&gt;&#039;allow reverse order ranges like 9-4 in addition to forward ranges&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; t = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; i = j + n &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; k - n &lt;span class=&quot;kw1&quot;&gt;Step&lt;/span&gt; n &#160;&lt;span class=&quot;co1&quot;&gt;&#039;only need the interior of range&lt;br&gt;
&lt;/span&gt; &#160; &#160; &#160; &#160;t = t &amp; &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt; &amp; &lt;span class=&quot;kw1&quot;&gt;CStr&lt;/span&gt;(i)&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt; i&lt;br&gt;
&#160; &lt;br&gt;
&#160; &#160; &#160; ps = Left$(ps, p - 1) &amp; t &amp; &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt; &amp; Mid$(ps, p + 1) &#160;&lt;span class=&quot;co1&quot;&gt;&#039;replace hyphen with interior of range&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; &#160; p = InStrRev(ps, &lt;span class=&quot;st0&quot;&gt;&quot;-&quot;&lt;/span&gt;, p - 1) &#160;&lt;span class=&quot;co1&quot;&gt;&#039;continue right to left!!&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Loop&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; foobar = Split(ps, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;)&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The 1st If check in prose:&lt;br&gt;
- can contain only decimal numerals, hyphens and commas&lt;br&gt;
- must start with a numeral&lt;br&gt;
- must end with a numeral&lt;br&gt;
- can&#039;t have substrings of 2 or more hyphens or commas&lt;br&gt;
- can&#039;t have 2 or more hyphens between commas&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Rick &#8211; regular expressions have been discussed before in this blog, and the blog is meant for more sophisticated users and developers, you know, those who aren&#8217;t afraid to do a bit of self-study.</p>
<p>You still have errors. Pass your latest function &#8220;1,2,&#8221; and it returns {&#8220;1?,&#8221;2?,&#8221;"}. Your validity checking fails when SInput begins or ends with a comma.</p>
<p>If you really insist on using Like patterns, then at least use them optimally.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Function</span> foobar(ps <span class="kw1">As</span> <span class="kw1">String</span>) <span class="kw1">As</span> <span class="kw1">Variant</span><br />
&nbsp; <span class="kw1">Dim</span> i <span class="kw1">As</span> <span class="kw1">Long</span>, j <span class="kw1">As</span> <span class="kw1">Long</span>, k <span class="kw1">As</span> <span class="kw1">Long</span>, n <span class="kw1">As</span> <span class="kw1">Long</span>, p <span class="kw1">As</span> <span class="kw1">Long</span>, t <span class="kw1">As</span> <span class="kw1">String</span></p>
<p>&nbsp; ps = Replace(ps, <span class="st0">&#8221; &#8220;</span>, <span class="st0">&#8220;&#8221;</span>) &nbsp;<span class="co1">&#8216;why not allow whitespace like Word does?<br />
</span><br />
&nbsp; <span class="kw1">If</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*[!0-9,-]*&#8221;</span> _<br />
&nbsp; &nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;[!0-9]*&#8221;</span> _<br />
&nbsp; &nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*[!0-9]&#8220;</span> _<br />
&nbsp; &nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*[,-][,-]*&#8221;</span> _<br />
&nbsp; &nbsp;<span class="kw1">Or</span> ps <span class="kw1">Like</span> <span class="st0">&#8220;*-[0-9]-*&#8221;</span> _<br />
&nbsp; &nbsp; <span class="kw1">Then</span> ps = <span class="st0">&#8220;&#8221;</span></p>
<p>&nbsp; p = InStrRev(ps, <span class="st0">&#8220;-&#8221;</span>) &nbsp;<span class="co1">&#8216;right to left!!<br />
</span><br />
&nbsp; <span class="kw1">Do</span> <span class="kw1">While</span> p &gt; 0<br />
&nbsp; &nbsp; i = InStrRev(ps, <span class="st0">&#8220;,&#8221;</span>, p &#8211; 1) + 1<br />
&nbsp; &nbsp; j = <span class="kw1">CLng</span>(Mid$(ps, i, p &#8211; i))<br />
&nbsp; &nbsp; i = InStr(p + 1, ps, <span class="st0">&#8220;,&#8221;</span>) &#8211; 1<br />
&nbsp; &nbsp; <span class="kw1">If</span> i = -1 <span class="kw1">Then</span> k = <span class="kw1">CLng</span>(Mid$(ps, p + 1)) <span class="kw1">Else</span> k = <span class="kw1">CLng</span>(Mid$(ps, p + 1, i &#8211; p))</p>
<p>&nbsp; &nbsp; <span class="kw1">If</span> j = k <span class="kw1">Then</span> &nbsp;<span class="co1">&#8216;allow trivial ranges like 3-3, but not much to do<br />
</span> &nbsp; &nbsp; &nbsp;ps = Left$(ps, p &#8211; 1) &amp; Mid$(ps, i + 1)</p>
<p>&nbsp; &nbsp; <span class="kw1">Else</span><br />
&nbsp; &nbsp; &nbsp; n = Sgn(k &#8211; j) &nbsp;<span class="co1">&#8216;allow reverse order ranges like 9-4 in addition to forward ranges<br />
</span><br />
&nbsp; &nbsp; &nbsp; t = <span class="st0">&#8220;&#8221;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">For</span> i = j + n <span class="kw1">To</span> k &#8211; n <span class="kw1">Step</span> n &nbsp;<span class="co1">&#8216;only need the interior of range<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp;t = t &amp; <span class="st0">&#8220;,&#8221;</span> &amp; <span class="kw1">CStr</span>(i)<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">Next</span> i<br />
&nbsp; <br />
&nbsp; &nbsp; &nbsp; ps = Left$(ps, p &#8211; 1) &amp; t &amp; <span class="st0">&#8220;,&#8221;</span> &amp; Mid$(ps, p + 1) &nbsp;<span class="co1">&#8216;replace hyphen with interior of range<br />
</span><br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span></p>
<p>&nbsp; &nbsp; p = InStrRev(ps, <span class="st0">&#8220;-&#8221;</span>, p &#8211; 1) &nbsp;<span class="co1">&#8216;continue right to left!!<br />
</span><br />
&nbsp; <span class="kw1">Loop</span></p>
<p>&nbsp; foobar = Split(ps, <span class="st0">&#8220;,&#8221;</span>)</p>
<p><span class="kw1">End</span> <span class="kw1">Function</span></div>
</div>
<p>The 1st If check in prose:<br />
- can contain only decimal numerals, hyphens and commas<br />
- must start with a numeral<br />
- must end with a numeral<br />
- can&#8217;t have substrings of 2 or more hyphens or commas<br />
- can&#8217;t have 2 or more hyphens between commas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gruff999</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48469</link>
		<dc:creator>gruff999</dc:creator>
		<pubDate>Fri, 30 Jul 2010 09:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48469</guid>
		<description>&lt;p&gt;&lt;a href=&quot;http://www.regular-expressions.info/&quot; rel=&quot;nofollow&quot;&gt;http://www.regular-expressions.info/&lt;/a&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><a href="http://www.regular-expressions.info/" rel="nofollow">http://www.regular-expressions.info/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Rothstein (MVP - Excel)</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48457</link>
		<dc:creator>Rick Rothstein (MVP - Excel)</dc:creator>
		<pubDate>Fri, 30 Jul 2010 03:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48457</guid>
		<description>&lt;p&gt;@ fzz&lt;/p&gt;
&lt;p&gt;&gt;&gt; your function dies on an untrapped error when passed &quot;-&quot; and returns {&quot;&quot;,&quot;&quot;} when passed &quot;,&quot;.&lt;/p&gt;
&lt;p&gt;I agree about regular expressions, but the last time I worked with them was on a UNIX system in the late 1980s, so RegEx pattern construction capabilities are a little rusty. Beside, I would guess most people following threads on this formum have little or no experience with them, so my code offers them a wholly native VB solution for them to digest. As for the state machine... too much extra code for my tastes. I think the above oversights on my part are easily corrected along with an error I had in my originally posted code (where I did a string rather than numeric comparison in the 2nd &quot;If&quot; statement inside the loop (which screwed up comparing a range like 9-11). Here is my modified code...&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;Function&lt;/span&gt; PagesToPrint(sInput &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;) &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Variant&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; X &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, Z &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, Temp &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;, sNumbers() &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;, sRange() &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*[!0-9,-]*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*,-*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-,*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*,,*&quot;&lt;/span&gt; _&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*--*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;-&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Or&lt;/span&gt; sInput &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; Bad&lt;br&gt;
&#160; sNumbers = Split(sInput, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; X = 0 &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;UBound&lt;/span&gt;(sNumbers)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sNumbers(X) &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; sNumbers(X) &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;*-*-*&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; Bad&lt;br&gt;
&#160; &#160; &#160; sRange = Split(sNumbers(X), &lt;span class=&quot;st0&quot;&gt;&quot;-&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;CLng&lt;/span&gt;(sRange(0)) &lt;= &lt;span class=&quot;kw1&quot;&gt;CLng&lt;/span&gt;(sRange(1)) &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; sNumbers(X) = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; Z = sRange(0) &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; sRange(1)&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; sNumbers(X) = sNumbers(X) &amp; &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt; &amp; Z&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; sNumbers(X) = Mid(sNumbers(X), 2)&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; Bad&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160; PagesToPrint = Split(Join(sNumbers, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;), &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Exit&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;br&gt;
Bad:&lt;br&gt;
&#160; PagesToPrint = Array()&lt;br&gt;
&#160; MsgBox &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &amp; sInput &amp; &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &amp; vbLf &amp; vbLf &amp; &lt;span class=&quot;st0&quot;&gt;&quot;The range of values you specified is incorrectly formed!&quot;&lt;/span&gt;, vbCritical&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>@ fzz</p>
<p>&gt;&gt; your function dies on an untrapped error when passed &#8220;-&#8221; and returns {&#8220;&#8221;,&#8221;"} when passed &#8220;,&#8221;.</p>
<p>I agree about regular expressions, but the last time I worked with them was on a UNIX system in the late 1980s, so RegEx pattern construction capabilities are a little rusty. Beside, I would guess most people following threads on this formum have little or no experience with them, so my code offers them a wholly native VB solution for them to digest. As for the state machine&#8230; too much extra code for my tastes. I think the above oversights on my part are easily corrected along with an error I had in my originally posted code (where I did a string rather than numeric comparison in the 2nd &#8220;If&#8221; statement inside the loop (which screwed up comparing a range like 9-11). Here is my modified code&#8230;</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Function</span> PagesToPrint(sInput <span class="kw1">As</span> <span class="kw1">String</span>) <span class="kw1">As</span> <span class="kw1">Variant</span><br />
&nbsp; <span class="kw1">Dim</span> X <span class="kw1">As</span> <span class="kw1">Long</span>, Z <span class="kw1">As</span> <span class="kw1">Long</span>, Temp <span class="kw1">As</span> <span class="kw1">String</span>, sNumbers() <span class="kw1">As</span> <span class="kw1">String</span>, sRange() <span class="kw1">As</span> <span class="kw1">String</span><br />
&nbsp; <span class="kw1">If</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*[!0-9,-]*&#8221;</span> <span class="kw1">Or</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*,-*&#8221;</span> <span class="kw1">Or</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*-,*&#8221;</span> <span class="kw1">Or</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*,,*&#8221;</span> _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Or</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;*&#8211;*&#8221;</span> <span class="kw1">Or</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;-&#8221;</span> <span class="kw1">Or</span> sInput <span class="kw1">Like</span> <span class="st0">&#8220;,&#8221;</span> <span class="kw1">Then</span> <span class="kw1">GoTo</span> Bad<br />
&nbsp; sNumbers = Split(sInput, <span class="st0">&#8220;,&#8221;</span>)<br />
&nbsp; <span class="kw1">For</span> X = 0 <span class="kw1">To</span> <span class="kw1">UBound</span>(sNumbers)<br />
&nbsp; &nbsp; <span class="kw1">If</span> sNumbers(X) <span class="kw1">Like</span> <span class="st0">&#8220;*-*&#8221;</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">If</span> sNumbers(X) <span class="kw1">Like</span> <span class="st0">&#8220;*-*-*&#8221;</span> <span class="kw1">Then</span> <span class="kw1">GoTo</span> Bad<br />
&nbsp; &nbsp; &nbsp; sRange = Split(sNumbers(X), <span class="st0">&#8220;-&#8221;</span>)<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">If</span> <span class="kw1">CLng</span>(sRange(0)) &lt;= <span class="kw1">CLng</span>(sRange(1)) <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sNumbers(X) = <span class="st0">&#8220;&#8221;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">For</span> Z = sRange(0) <span class="kw1">To</span> sRange(1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sNumbers(X) = sNumbers(X) &amp; <span class="st0">&#8220;,&#8221;</span> &amp; Z<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Next</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sNumbers(X) = Mid(sNumbers(X), 2)<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">GoTo</span> Bad<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; <span class="kw1">Next</span><br />
&nbsp; PagesToPrint = Split(Join(sNumbers, <span class="st0">&#8220;,&#8221;</span>), <span class="st0">&#8220;,&#8221;</span>)<br />
&nbsp; <span class="kw1">Exit</span> <span class="kw1">Function</span><br />
Bad:<br />
&nbsp; PagesToPrint = Array()<br />
&nbsp; MsgBox <span class="st0">&#8220;&#8221;</span><span class="st0">&#8220;&#8221;</span> &amp; sInput &amp; <span class="st0">&#8220;&#8221;</span><span class="st0">&#8220;&#8221;</span> &amp; vbLf &amp; vbLf &amp; <span class="st0">&#8220;The range of values you specified is incorrectly formed!&#8221;</span>, vbCritical<br />
<span class="kw1">End</span> <span class="kw1">Function</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/29/pages-to-print/#comment-48453</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Fri, 30 Jul 2010 01:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4070#comment-48453</guid>
		<description>&lt;p&gt;@Rick - your function dies on an untrapped error when passed &quot;-&quot; and returns {&quot;&quot;,&quot;&quot;} when passed &quot;,&quot;.&lt;/p&gt;
&lt;p&gt;Nothing beats regular expressions for text parsing and lexical validity testing. &#039;Course it helps to get the regex right. My first re.Pattern statement should have been&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;re.Pattern = &lt;span class=&quot;st0&quot;&gt;&quot;^((d+-d+&#124;d+),)*(d+-d+&#124;d+)$&quot;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You CAN check the validity of the input string without regular expressions by using a formal state machine. Not pretty, but a lot more robust than screwing around trying to use Like to match and exhaustive set of compound tokens.&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;Function&lt;/span&gt; PGRNGvalchk(ps &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;) &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Boolean&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Const&lt;/span&gt; PATsep &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt; * 1 = &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;, STsep &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt; = 1&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Const&lt;/span&gt; PATnum &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt; = &lt;span class=&quot;st0&quot;&gt;&quot;[0-9]&quot;&lt;/span&gt;, STnum &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt; = 2&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Const&lt;/span&gt; PATrng &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt; * 1 = &lt;span class=&quot;st0&quot;&gt;&quot;-&quot;&lt;/span&gt;, STrng &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt; = 4, STend &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt; = STnum + STrng&lt;br&gt;
&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; ch &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt; * 1, k &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, n &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, st &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;&lt;br&gt;
&#160; &lt;br&gt;
&#160; ps = Replace(ps, &lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;, &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;)&lt;br&gt;
&#160; n = Len(ps)&lt;br&gt;
&lt;br&gt;
&#160; st = STsep&lt;br&gt;
&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; k = 1 &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; n&lt;br&gt;
&#160; &#160; ch = Mid$(ps, k, 1)&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Select&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; st&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; STsep:&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; ch &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; PATnum &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; st = STnum &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt; st = 0&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; STnum:&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; ch &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; PATsep &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; st = STsep&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;ElseIf&lt;/span&gt; ch &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; PATrng &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; st = STrng&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;ElseIf&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; ch &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; PATnum &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; st = 0&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; STrng:&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; ch &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; PATnum &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; st = STend &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt; st = 0&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; STend:&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; ch &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; PATsep &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; st = STsep&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;ElseIf&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; ch &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; PATnum &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; st = 0&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Case&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;:&lt;br&gt;
&#160; &#160; &#160; st = 0&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Select&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; st = 0 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Exit&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt; k&lt;br&gt;
&lt;br&gt;
&#160; PGRNGvalchk = (st &lt;span class=&quot;kw1&quot;&gt;And&lt;/span&gt; STnum)&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>@Rick &#8211; your function dies on an untrapped error when passed &#8220;-&#8221; and returns {&#8220;&#8221;,&#8221;"} when passed &#8220;,&#8221;.</p>
<p>Nothing beats regular expressions for text parsing and lexical validity testing. &#8216;Course it helps to get the regex right. My first re.Pattern statement should have been</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer">re.Pattern = <span class="st0">&#8220;^((d+-d+|d+),)*(d+-d+|d+)$&#8221;</span></div>
</div>
<p>You CAN check the validity of the input string without regular expressions by using a formal state machine. Not pretty, but a lot more robust than screwing around trying to use Like to match and exhaustive set of compound tokens.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Function</span> PGRNGvalchk(ps <span class="kw1">As</span> <span class="kw1">String</span>) <span class="kw1">As</span> <span class="kw1">Boolean</span><br />
&nbsp; <span class="kw1">Const</span> PATsep <span class="kw1">As</span> <span class="kw1">String</span> * 1 = <span class="st0">&#8220;,&#8221;</span>, STsep <span class="kw1">As</span> <span class="kw1">Long</span> = 1<br />
&nbsp; <span class="kw1">Const</span> PATnum <span class="kw1">As</span> <span class="kw1">String</span> = <span class="st0">&#8220;[0-9]&#8220;</span>, STnum <span class="kw1">As</span> <span class="kw1">Long</span> = 2<br />
&nbsp; <span class="kw1">Const</span> PATrng <span class="kw1">As</span> <span class="kw1">String</span> * 1 = <span class="st0">&#8220;-&#8221;</span>, STrng <span class="kw1">As</span> <span class="kw1">Long</span> = 4, STend <span class="kw1">As</span> <span class="kw1">Long</span> = STnum + STrng</p>
<p>&nbsp; <span class="kw1">Dim</span> ch <span class="kw1">As</span> <span class="kw1">String</span> * 1, k <span class="kw1">As</span> <span class="kw1">Long</span>, n <span class="kw1">As</span> <span class="kw1">Long</span>, st <span class="kw1">As</span> <span class="kw1">Long</span><br />
&nbsp; <br />
&nbsp; ps = Replace(ps, <span class="st0">&#8221; &#8220;</span>, <span class="st0">&#8220;&#8221;</span>)<br />
&nbsp; n = Len(ps)</p>
<p>&nbsp; st = STsep</p>
<p>&nbsp; <span class="kw1">For</span> k = 1 <span class="kw1">To</span> n<br />
&nbsp; &nbsp; ch = Mid$(ps, k, 1)</p>
<p>&nbsp; &nbsp; <span class="kw1">Select</span> <span class="kw1">Case</span> st<br />
&nbsp; &nbsp; <span class="kw1">Case</span> STsep:<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">If</span> ch <span class="kw1">Like</span> PATnum <span class="kw1">Then</span> st = STnum <span class="kw1">Else</span> st = 0</p>
<p>&nbsp; &nbsp; <span class="kw1">Case</span> STnum:<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">If</span> ch <span class="kw1">Like</span> PATsep <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; st = STsep<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">ElseIf</span> ch <span class="kw1">Like</span> PATrng <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; st = STrng<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">ElseIf</span> <span class="kw1">Not</span> ch <span class="kw1">Like</span> PATnum <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; st = 0<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span></p>
<p>&nbsp; &nbsp; <span class="kw1">Case</span> STrng:<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">If</span> ch <span class="kw1">Like</span> PATnum <span class="kw1">Then</span> st = STend <span class="kw1">Else</span> st = 0</p>
<p>&nbsp; &nbsp; <span class="kw1">Case</span> STend:<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">If</span> ch <span class="kw1">Like</span> PATsep <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; st = STsep<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">ElseIf</span> <span class="kw1">Not</span> ch <span class="kw1">Like</span> PATnum <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; st = 0<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span></p>
<p>&nbsp; &nbsp; <span class="kw1">Case</span> <span class="kw1">Else</span>:<br />
&nbsp; &nbsp; &nbsp; st = 0</p>
<p>&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">Select</span></p>
<p>&nbsp; &nbsp; <span class="kw1">If</span> st = 0 <span class="kw1">Then</span> <span class="kw1">Exit</span> <span class="kw1">For</span></p>
<p>&nbsp; <span class="kw1">Next</span> k</p>
<p>&nbsp; PGRNGvalchk = (st <span class="kw1">And</span> STnum)</p>
<p><span class="kw1">End</span> <span class="kw1">Function</span></div>
</div>
]]></content:encoded>
	</item>
</channel>
</rss>

