<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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>Daily Dose of Excel</title>
	<atom:link href="http://www.dailydoseofexcel.com/index.php?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com</link>
	<description>Daily posts of Excel tips...and other stuff</description>
	<pubDate>Wed, 01 Jul 2009 18:24:57 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>June Stats</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/07/01/june-stats/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/07/01/june-stats/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 18:24:57 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2685</guid>
		<description><![CDATA[The Spreadsheet Page
Pointy Haired Dilbert

]]></description>
			<content:encoded><![CDATA[<p><a href="http://spreadsheetpage.com/index.php/comments/visitor_stats/#c">The Spreadsheet Page</a><br />
<a href="http://chandoo.org/wp/2009/07/01/best-month-ever/">Pointy Haired Dilbert</a></p>
<p><img src="http://www.dailydoseofexcel.com/blogpix/june09stats.gif" height="283" width="401" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/07/01/june-stats/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Interrupting Calculations</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/07/01/interrupting-calculations/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/07/01/interrupting-calculations/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 16:03:52 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2682</guid>
		<description><![CDATA[Normally, Excel calculates your workbooks so fast you don&#8217;t notice.  Sometimes, however, your workbook is so big that it takes Excel some time to calculate it.  I&#8217;m guessing readers of this blog run into that situation more than the average Joe.  While Excel is calculating, the status bar displays its progress.  [...]]]></description>
			<content:encoded><![CDATA[<p>Normally, Excel calculates your workbooks so fast you don&#8217;t notice.  Sometimes, however, your workbook is so big that it takes Excel some time to calculate it.  I&#8217;m guessing readers of this blog run into that situation more than the average Joe.  While Excel is calculating, the status bar displays its progress.  If you continue to work during the calculation, Excel will pause its calculation so you can work at a normal speed.  Nice feature, I think.</p>
<p>Excel in mid-calculation<br />
<img src="http://www.dailydoseofexcel.com/blogpix/calcinterrupt1.gif" height="39" width="262" alt="" /></p>
<p>Make a keystroke and it goes back to ready, but shows that more calc&#8217;ing is needed<br />
<img src="http://www.dailydoseofexcel.com/blogpix/calcinterrupt2.gif" height="38" width="195" alt="" /></p>
<p>I guess Microsoft is assuming that if you doing other things, you&#8217;re not really looking at the results.  If you&#8217;re not looking at the results, it can wait until you&#8217;re done to finish calculating.  For humans, I think that&#8217;s a fine assumption.  For VBA code, not so much.  Your code may be continuing on happily without knowing that the workbook isn&#8217;t fully calculated.</p>
<p>The Excel object model provides the Application.CalculationInterruptKey property to control how/if calculation can be interrupted.  <strong>xlAnyKey</strong> is the default and it pauses whenever the user starts working.  <strong>xlEscKey</strong> only pauses when the escape key is pressed.  It&#8217;s used when you want to allow the user to interrupt calculation, but you want to make sure they do it explicitly and not by accident.  <strong>xlNoKey</strong> prevents interruption.  It seems that any time you calculate in code, you should set this property to xlNoKey, then set it back.  Are there times it wouldn&#8217;t matter?</p>
<p>Thanks to Bill Manville for &#8220;discovering&#8221; the CalculationInterruptKey property.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/07/01/interrupting-calculations/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Quick PivotTables</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/29/quick-pivottables/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/06/29/quick-pivottables/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 15:41:56 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Pivot Tables]]></category>

		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2654</guid>
		<description><![CDATA[
Sometime in the mid-1990s, a man named Lyle Lanley walked into Microsoft with an idea.  Probably the greatest....  Oh, it's more of an Apple idea.  "Just tell us the idea and we'll implement it", said Bill Gates.
I'm on a quest to rid my life of wizards.  The wizards that Microsoft seems [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.dailydoseofexcel.com/blogpix/pivotwizard.gif" height="261" width="140" align="right" alt="" /></p>
<p>Sometime in the mid-1990s, a man named Lyle Lanley walked into Microsoft with an idea.  Probably the greatest....  Oh, it's more of an Apple idea.  "Just tell us the idea and we'll implement it", said Bill Gates.</p>
<p>I'm on a quest to rid my life of wizards.  The wizards that Microsoft seems to use for every single command.  It all started with <a href="http://www.dailydoseofexcel.com/archives/2009/02/18/inflexible-find/">fixing the find dialog</a> as I grew tired of clicking the Options button.  Then I saw an opportunity to speed up <a href="http://www.dailydoseofexcel.com/archives/2009/03/01/quick-text-to-columns-utility/">Text to Columns</a> which is unnecessarily wizardish.  Today's victim is the Pivot Table.</p>
<p>Have you seen the wizard for Pivot tables?  They couldn't put that on one screen?  Well I say, No more!  I just want to make a pivot table:</p>
<ul>
<li>from an Excel range</li>
<li>that I've already selected</li>
<li>and I want it on a new sheet</li>
</ul>
<p>Almost always.  Unless I need something out of the ordinary, I'm using this code:</p>
<div class="syntax_hilite">
<div id="vb-2">
<div class="vb"><span style="color: #0000DD;">Sub</span> CreatePivotTable<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> rData <span style="color: #0000DD;">As</span> Range<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> shNew <span style="color: #0000DD;">As</span> Worksheet<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> pcNew <span style="color: #0000DD;">As</span> PivotCache<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> rCell <span style="color: #0000DD;">As</span> Range<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> lFieldCnt <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> ptNew <span style="color: #0000DD;">As</span> PivotTable<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">Const</span> sFIELD <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span> = <span style="color: #ff0000;">"Field"</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007F00;">'Make sure a range is selected</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">TypeName</span><span style="color:#008800;">&#40;</span>Selection<span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"Range"</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Set</span> rData = Selection.CurrentRegion<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Set</span> shNew = rData.Parent.Parent.Sheets.Add<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'put column headers in blank cells</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; lFieldCnt = <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> <span style="color: #0000DD;">Each</span> rCell <span style="color: #0000DD;">In</span> rData.Rows<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>.Cells<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">IsEmpty</span><span style="color:#008800;">&#40;</span>rCell.Value<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rCell.Value = sFIELD &amp; lFieldCnt<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lFieldCnt = lFieldCnt + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> rCell<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Set</span> pcNew = shNew.Parent.PivotCaches.Add<span style="color:#008800;">&#40;</span>xlDatabase, rData<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Set</span> ptNew = shNew.PivotTables.Add<span style="color:#008800;">&#40;</span>pcNew, shNew.Cells<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; ptNew.AddFields rData.Rows<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>.Cells<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>.<span style="color: #0000DD;">Text</span>, rData.Rows<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>.Cells<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span>.<span style="color: #0000DD;">Text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ptNew.AddDataField ptNew.PivotFields<span style="color:#008800;">&#40;</span>rData.Rows<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>.Cells<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>.<span style="color: #0000DD;">Text</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>Those last two lines add row, column, and data fields from the first three columns of the data.  I don't like that, as it's prone to error.  What I like less is what I get when I exclude those lines.</p>
<p><img src="http://www.dailydoseofexcel.com/blogpix/blankpivottable.gif" height="241" width="295" alt="" /></p>
<p>Compare four blank blue boxes to what you get via the user interface</p>
<p><img src="http://www.dailydoseofexcel.com/blogpix/blankpivottable2.gif" height="444" width="543" alt="" /></p>
<p>I don't like the four blank squares and I don't like using the first three columns.  I have to find something better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/06/29/quick-pivottables/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Animate a greeting with Excel and VBA</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/27/animate-a-greeting-with-excel-and-vba/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/06/27/animate-a-greeting-with-excel-and-vba/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 22:44:34 +0000</pubDate>
		<dc:creator>Tushar Mehta</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2674</guid>
		<description><![CDATA[Inspired by Dick's XL birthday, the upcoming birthday of my fiancee, and tinkering with iphone app development, I thought of an animated greeting in the form of a stadium wave (known to some as an audience wave)...




See http://www.tushar-mehta.com/publish_train/xl_vba_cases/greeting_wave.html
]]></description>
			<content:encoded><![CDATA[<p>Inspired by Dick's XL birthday, the upcoming birthday of my fiancee, and tinkering with iphone app development, I thought of an animated greeting in the form of a stadium wave (known to some as an audience wave)...</p>
<p><img class="alignleft size-full wp-image-2665" title="imga1" src="http://www.dailydoseofexcel.com/blogpix/imga1.gif" alt="imga1" width="929" height="156" /><br />
<img class="alignleft size-full wp-image-2666" title="img151" src="http://www.dailydoseofexcel.com/blogpix/img151.gif" alt="img151" width="931" height="159" /><br />
<img class="alignleft size-full wp-image-2667" title="img171" src="http://www.dailydoseofexcel.com/blogpix/img171.gif" alt="img171" width="956" height="150" /><br />
<img class="alignleft size-full wp-image-2668" title="img191" src="http://www.dailydoseofexcel.com/blogpix/img191.gif" alt="img191" width="979" height="168" /><br />
See <a href="http://www.tushar-mehta.com/publish_train/xl_vba_cases/greeting_wave.html" target="_blank">http://www.tushar-mehta.com/publish_train/xl_vba_cases/greeting_wave.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/06/27/animate-a-greeting-with-excel-and-vba/feed/</wfw:commentRss>
		</item>
		<item>
		<title>XL</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/26/xl/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/06/26/xl/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 13:36:28 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2651</guid>
		<description><![CDATA[
If I were Roman, that's how old I would be today.
Today I will be spending my birthday processing inventory transactions and answering the phone - great fun.  Tomorrow, however, we're having a little shindig in my honor with family, friends, and beer.
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.dailydoseofexcel.com/blogpix/toga.gif" height="240" width="160" align="right" alt="" /></p>
<p>If I were Roman, that's how old I would be today.</p>
<p>Today I will be spending my birthday processing inventory transactions and answering the phone - great fun.  Tomorrow, however, we're having a little shindig in my honor with family, friends, and beer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/06/26/xl/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Euler Problem 83</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/23/euler-problem-83/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/06/23/euler-problem-83/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 01:13:20 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2621</guid>
		<description><![CDATA[Euler Problem 83 asks:

NOTE: This problem is a significantly more challenging version of Problem 81.
In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom right, by moving left, right, up, and down, is indicated in red and is equal to 2297.

131 673 234 103 18
201 96  [...]]]></description>
			<content:encoded><![CDATA[<p>Euler Problem 83 asks:</p>
<blockquote><p>
NOTE: This problem is a significantly more challenging version of Problem 81.</p>
<p>In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom right, by moving left, right, up, and down, is indicated in red and is equal to 2297.</p>
<pre>
<font color="red">131</font> 673 <font color="red">234 103 18</font>
<font color="red">201 96  342</font> 965 <font color="red">150</font>
630 803 746 <font color="red">422 111</font>
537 699 497 <font color="red">121</font> 956
805 732 524 <font color="red">37  331</font>
</pre>
<p>Find the minimal path sum, in matrix.txt (right click and 'Save Link/Target As...'), a 31K text file containing a 80 by 80 matrix, from the top left to the bottom right by moving left, right, up, and down.
</p></blockquote>
<p>In the <a href="http://www.dailydoseofexcel.com/archives/2009/06/15/euler-problem-123/">Problem 123 thread</a> Doug Jenkins provided a spreadsheet solution for Problem 83, as well as suggesting an alternate method to solve the problem by padding the matrix. He thereby relieved a huge mental block of mine, but it's in the wrong thread.  So I started this one.</p>
<p>Padding the matrix has its advantage.  It allows you to use a common relationship in the area of interest without having to worry about variable subscripts being out of range because you'd otherwise reference a row or column that you haven't dimensioned (akin to trying to reference Row(0) on a spreadsheet.)  There's some overhead to do this, but it saves special cases at the corners and borders.  Doug recommended using 1000000, and that's as good a choice as any.  With that in mind, the above matrix comes to look like this:</p>
<pre>
1000000 1000000 1000000 1000000 1000000 1000000 1000000
1000000   131     673     234     103     18    1000000
1000000   201     96      342     965     150   1000000
1000000   630     803     746     422     111   1000000
1000000   537     699     497     121     956   1000000
1000000   805     732     524     37      331   1000000
1000000 1000000 1000000 1000000 1000000 1000000 1000000
</pre>
<p>Since a picture = 1 kiloword, you can see how we have slop all the way around for subscripts, with the added advantage that if you make the matrix zero-based, the action starts at Row(1), Column(1).  My mind likes it better that way.  I used this same padding trick for Problem 67, where you can turn a triangle into a square.  It really simplifies the code.  With all that for background, here is my code that turns Doug's spreadsheet solution into VBA.  It runs in about 3/10's of a second.</p>
<div class="syntax_hilite">
<div id="vb-4">
<div class="vb"><span style="color: #0000DD;">Sub</span> Problem_083<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
<span style="color: #0000DD;">Dim</span> Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">81</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Variant</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Cell<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">81</span>, <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">81</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> R <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, C <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> <span style="color: #0000DD;">Min</span>&nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Answer <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, T <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Single</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> TEMP1 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, TEMP2 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> NumRows <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, NumCols <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> IsTest <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Boolean</span>, i <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Const</span> <span style="color: #0000DD;">text</span>&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span> = <span style="color: #ff0000;">"D:\Downloads\Euler\matrix.txt"</span><br />
&nbsp;<br />
&nbsp; &nbsp;T = <span style="color: #0000DD;">Timer</span><br />
&nbsp;<br />
&nbsp; &nbsp;R = <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Open</span> <span style="color: #0000DD;">text</span> <span style="color: #0000DD;">For</span> <span style="color: #0000DD;">Input</span> <span style="color: #0000DD;">As</span> #1&nbsp; &nbsp;<span style="color: #007F00;">'80 lines, comma delimited</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Do</span> <span style="color: #0000DD;">While</span> <span style="color: #0000DD;">Not</span> <span style="color: #0000DD;">EOF</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Line</span> <span style="color: #0000DD;">Input</span> #1, Matrix<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<span style="color: #007F00;">'fills rows 1 to 80; 0 and 81 come later</span><br />
&nbsp; &nbsp; &nbsp; R = R + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Loop</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Close</span> #1<br />
&nbsp;<br />
&nbsp; &nbsp;IsTest = False<br />
&nbsp; &nbsp;<span style="color: #0000DD;">If</span> IsTest <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; NumRows = <span style="color: #cc66cc;">6</span><br />
&nbsp; &nbsp; &nbsp; NumCols = <span style="color: #cc66cc;">6</span><br />
&nbsp; &nbsp; &nbsp; Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"131,673,234,103,18"</span><br />
&nbsp; &nbsp; &nbsp; Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"201,96,342,965,150"</span><br />
&nbsp; &nbsp; &nbsp; Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"630,803,746,422,111"</span><br />
&nbsp; &nbsp; &nbsp; Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"537,699,497,121,956"</span><br />
&nbsp; &nbsp; &nbsp; Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"805,732,524,37,331"</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; NumRows = <span style="color: #cc66cc;">81</span><br />
&nbsp; &nbsp; &nbsp; NumCols = <span style="color: #cc66cc;">81</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> C = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> NumCols - <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span> = Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span> &amp;amp; <span style="color: #ff0000;">"1000000 "</span>&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'adds top padding @(0), sets up TRIM()</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> C<br />
&nbsp; &nbsp;Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span> = Replace<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Trim</span><span style="color:#008800;">&#40;</span>Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span>, <span style="color: #ff0000;">" "</span>, <span style="color: #ff0000;">","</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<span style="color: #007F00;">'makes it comma-delimited</span><br />
&nbsp; &nbsp;Matrix<span style="color:#008800;">&#40;</span>NumRows<span style="color:#008800;">&#41;</span> = Matrix<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<span style="color: #007F00;">' adds bottom padding @(NumRows)</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> R = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> NumRows<br />
&nbsp; &nbsp; &nbsp; Matrix<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"1000000,"</span> &amp;amp; Matrix<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span> &amp;amp; <span style="color: #ff0000;">",1000000"</span>&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #007F00;">' pads all rows left and right</span><br />
&nbsp; &nbsp; &nbsp; Matrix<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">Split</span><span style="color:#008800;">&#40;</span>Matrix<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span>, <span style="color: #ff0000;">","</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'makes a zero-based NumRows X NumCols matrix</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> R<br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> R = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> NumRows<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> C = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> NumCols<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Cell<span style="color:#008800;">&#40;</span>R, C<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Matrix<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">If</span> C GT <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">Then</span> Cell<span style="color:#008800;">&#40;</span>R, C<span style="color:#008800;">&#41;</span> = Cell<span style="color:#008800;">&#40;</span>R, C<span style="color:#008800;">&#41;</span> + Cell<span style="color:#008800;">&#40;</span>R, C - <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #007F00;">' seeds the Cell array</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> C<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> R<br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Do</span><br />
&nbsp; &nbsp; &nbsp; TEMP1 = Cell<span style="color:#008800;">&#40;</span>NumRows - <span style="color: #cc66cc;">1</span>, NumCols - <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'start value of unpadded LR corner</span><br />
&nbsp; &nbsp; &nbsp; i = i + <span style="color: #cc66cc;">1</span>&nbsp; &nbsp;<span style="color: #007F00;">'counts iterations</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> R = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> NumRows - <span style="color: #cc66cc;">1</span>&nbsp; &nbsp;<span style="color: #007F00;">'inside the padding</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">For</span> C = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> NumCols - <span style="color: #cc66cc;">1</span>&nbsp; &nbsp;<span style="color: #007F00;">'inside the padding</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> R = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">And</span> C = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">Then</span>&nbsp; &nbsp;<span style="color: #007F00;">'reset Cell(1,1) from above</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Cell<span style="color:#008800;">&#40;</span>R, C<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Matrix<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Else</span>&nbsp; &nbsp;<span style="color: #007F00;">'do the hard work</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Min</span> = Application.WorksheetFunction.<span style="color: #0000DD;">Min</span><span style="color:#008800;">&#40;</span>Cell<span style="color:#008800;">&#40;</span>R + <span style="color: #cc66cc;">1</span>, C<span style="color:#008800;">&#41;</span>, Cell<span style="color:#008800;">&#40;</span>R - <span style="color: #cc66cc;">1</span>, C<span style="color:#008800;">&#41;</span>, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Cell<span style="color:#008800;">&#40;</span>R, C + <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>, Cell<span style="color:#008800;">&#40;</span>R, C - <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Cell<span style="color:#008800;">&#40;</span>R, C<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Matrix<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span> + <span style="color: #0000DD;">Min</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Next</span> C<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> R<br />
&nbsp; &nbsp; &nbsp; TEMP2 = Cell<span style="color:#008800;">&#40;</span>NumRows - <span style="color: #cc66cc;">1</span>, NumCols - <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'finish value of unpadded LR corner</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> i GT NumRows * NumCols <span style="color: #0000DD;">Then</span> <span style="color: #0000DD;">Exit</span> <span style="color: #0000DD;">Do</span>&nbsp; &nbsp;<span style="color: #007F00;">'escape clause</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Loop</span> <span style="color: #0000DD;">Until</span> TEMP1 = TEMP2&nbsp; &nbsp;<span style="color: #007F00;">'stable when start = finish</span><br />
&nbsp;<br />
&nbsp; &nbsp;Answer = Cell<span style="color:#008800;">&#40;</span>NumRows - <span style="color: #cc66cc;">1</span>, NumCols - <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> Answer; <span style="color: #ff0000;">"&nbsp; Time:"</span>; <span style="color: #0000DD;">Timer</span> - T, i<br />
&nbsp;<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>Doug mentions seeding the Cell array.  This makes a huge difference.  It goes through the Do-Loop only 5 times.  The answer is known after 4 loops, but it takes 5 for the starting TEMP1 to know it.  I couldn't figure out how to avoid that without apriori knowledge of the Answer, which is in the bottom right cell before the padding.</p>
<p>Playing with the spreadsheet solution, I made a third matrix of the array by "pasting special" a copy when all is stable.  Then with conditional formatting comparing the two, I could see how the data flows and settles as I stepped through it.  It starts from the upper left in kind of a maple-leaf pattern:  Strong down the middle, with a spike above and below, and then a weak spike down the left side and the top edge.  It takes 11 reps for everything to stabilize. </p>
<p>So, all in all, this is my VBA for Doug's concept.  Stephen B and Josh G have other approaches, and hopefully, they'll share.   This code is the combination of two half-good ideas I had.  Maybe Doug will chime in, too.  He's the one who gave me the clue about the whole approach.</p>
<p>The usual angle bracket corrections are in the code. It's interesting that it's Cell(R,C) but Matrix (R)(C) for the syntax.</p>
<p>...mrt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/06/23/euler-problem-83/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Euler Problem 81</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/20/euler-problem-81/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/06/20/euler-problem-81/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 15:46:20 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2607</guid>
		<description><![CDATA[Euler Problem 81 asks:

In the 5 by 5 matrix below, the minimal path Min from the top left to the bottom right,
by only moving to the right and down, is indicated in red and is equal to 2427.

131   673   234   103   18
201   96   [...]]]></description>
			<content:encoded><![CDATA[<p>Euler Problem 81 asks:</p>
<blockquote><p>
In the 5 by 5 matrix below, the minimal path Min from the top left to the bottom right,<br />
by only moving to the right and down, is indicated in red and is equal to 2427.</p>
<pre>
<font color="red">131</font>   673   234   103   18
<font color="red">201   96    342</font>   965   150
630   803   <font color="red">746   422</font>   111
537   699   497   <font color="red">121</font>   956
805   732   524   <font color="red">37    331</font>
</pre>
<p>Find the minimal path Min, in matrix.txt (right click and 'Save Link/Target As...'),<br />
a 31K text file containing a 80 by 80 matrix, from the top left to the bottom right<br />
by only moving right and down.
</p></blockquote>
<p>This is very similar to problems 18 and 67, except that they ask for the maximum path to the bottom, not the minimum path to the lower right corner.  #81 can absolutely be done in a spreadsheet, as Tushar shows <a href="http://www.tushar-mehta.com/misc_tutorials/project_euler/index.html">here</a> for numbers 18 and  67.  I like to solve them in VBA.  The difference between this problem and #67 is that we have to get to a specific matrix cell, and by the rules, if we end up at the right edge, we can only go down, and if we end up at the bottom, we can only go right.  In other words, on the right, progressively sum upwards from the lower right corner, and on the bottom, progressively sum leftwards from that same corner.  The goal is to abstract the problem so the choice at matrix cell(0)(0) is the minimum of all paths to cell(0)(0).  The answer will be the sum of cell(0)(0) and that minimum.  Here is my code that does this.  It runs in a blink (less that a tenth of a second.)</p>
<div class="syntax_hilite">
<div id="vb-6">
<div class="vb"><span style="color: #0000DD;">Sub</span> Problem_081<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Cell<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">79</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Variant</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> R <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, C <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> NumRows <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, NumCols <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> <span style="color: #0000DD;">Min</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, IsTest <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Boolean</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Answer <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, T <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Single</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Const</span> <span style="color: #0000DD;">text</span>&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span> = <span style="color: #ff0000;">"D:\Downloads\Euler\matrix.txt"</span><br />
&nbsp;<br />
&nbsp; &nbsp;T = <span style="color: #0000DD;">Timer</span><br />
&nbsp;<br />
&nbsp; &nbsp;R = <span style="color: #cc66cc;">0</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Open</span> <span style="color: #0000DD;">text</span> <span style="color: #0000DD;">For</span> <span style="color: #0000DD;">Input</span> <span style="color: #0000DD;">As</span> #1&nbsp; &nbsp;<span style="color: #007F00;">'80 lines, comma delimited</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Do</span> <span style="color: #0000DD;">While</span> <span style="color: #0000DD;">Not</span> <span style="color: #0000DD;">EOF</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Line</span> <span style="color: #0000DD;">Input</span> #1, Cell<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; R = R + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Loop</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Close</span> #1<br />
&nbsp; <br />
&nbsp; &nbsp;IsTest = False<br />
&nbsp; &nbsp;<span style="color: #0000DD;">If</span> IsTest <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; NumRows = <span style="color: #cc66cc;">4</span><br />
&nbsp; &nbsp; &nbsp; NumCols = <span style="color: #cc66cc;">4</span><br />
&nbsp; &nbsp; &nbsp; Cell<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"131,673,234,103,18"</span><br />
&nbsp; &nbsp; &nbsp; Cell<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"201,96,342,965,150"</span><br />
&nbsp; &nbsp; &nbsp; Cell<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"630,803,746,422,111"</span><br />
&nbsp; &nbsp; &nbsp; Cell<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"537,699,497,121,956"</span><br />
&nbsp; &nbsp; &nbsp; Cell<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"805,732,524,37,331"</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; NumRows = <span style="color: #cc66cc;">79</span><br />
&nbsp; &nbsp; &nbsp; NumCols = <span style="color: #cc66cc;">79</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> R = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> NumRows<br />
&nbsp; &nbsp; &nbsp; Cell<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">Split</span><span style="color:#008800;">&#40;</span>Cell<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span>, <span style="color: #ff0000;">","</span><span style="color:#008800;">&#41;</span> <span style="color: #007F00;">' making a NumRows X NumCols matrix</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> R<br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> C = NumCols - <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">Step</span> -<span style="color: #cc66cc;">1</span> <span style="color: #007F00;">'rolling up right and bottom edges</span><br />
&nbsp; &nbsp; &nbsp; R = C<br />
&nbsp; &nbsp; &nbsp; Cell<span style="color:#008800;">&#40;</span>NumRows<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Cell<span style="color:#008800;">&#40;</span>NumRows<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span> + <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Cell<span style="color:#008800;">&#40;</span>NumRows<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C + <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; Cell<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>NumCols<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Cell<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>NumCols<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span> + <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Cell<span style="color:#008800;">&#40;</span>R + <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>NumCols<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> C<br />
&nbsp; <br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> R = NumRows - <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">Step</span> -<span style="color: #cc66cc;">1</span> <span style="color: #007F00;">'rolling up the minimums</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> C = NumCols - <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">Step</span> -<span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Min</span> = Application.WorksheetFunction.<span style="color: #0000DD;">Min</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Cell<span style="color:#008800;">&#40;</span>R + <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span>, <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Cell<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C + <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Cell<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span>Cell<span style="color:#008800;">&#40;</span>R<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span>C<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span> + <span style="color: #0000DD;">Min</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> C<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> R<br />
&nbsp; <br />
&nbsp; &nbsp;Answer = Cell<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> Answer; <span style="color: #ff0000;">"&nbsp; Time:"</span>; <span style="color: #0000DD;">Timer</span> - T<br />
&nbsp; <br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>Having done #67, this was very straight forward.  Problem #83, which uses the same matrix, is similar but harder.  It's having its way with me.  Here is #83:</p>
<blockquote><p>
NOTE: This problem is a significantly more challenging version of Problem 81.</p>
<p>In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom right, by moving left, right, up, and down, is indicated in red and is equal to 2297.</p>
<pre>
<font color="red">131</font> 673 <font color="red">234 103 18</font>
<font color="red">201 96  342</font> 965 <font color="red">150</font>
630 803 746 <font color="red">422 111</font>
537 699 497 <font color="red">121</font> 956
805 732 524 <font color="red">37  331</font>
</pre>
<p>Find the minimal path sum, in matrix.txt (right click and 'Save Link/Target As...'), a 31K text file containing a 80 by 80 matrix, from the top left to the bottom right by moving left, right, up, and down.
</p></blockquote>
<p>Note the NOTE, the rules change, and the snaking path.  It takes 12 moves, whereas #81 only takes 8.   The minimum on the left depends on the minimum on the right.  As Doug J has said, 'tis circular, and I've not grasped it yet.  The various code I've written does the example, but either takes more than 6400 moves (visiting every cell several times) or ends up in an endless loop in the lower right corner of matrix.txt.</p>
<p>...mrt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/06/20/euler-problem-81/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Look Up</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/19/look-up/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/06/19/look-up/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 18:19:00 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2604</guid>
		<description><![CDATA[The last control on the right click menu is Look Up.  That opens the Research task pane.

I'd be interested to know if anyone actually uses this.  I accidentally click on it several times a week, but I don't actually use it.  Anyone?
]]></description>
			<content:encoded><![CDATA[<p>The last control on the right click menu is Look Up.  That opens the Research task pane.</p>
<p><img src="http://www.dailydoseofexcel.com/blogpix/research1.gif" height="239" width="200" alt="" /></p>
<p>I'd be interested to know if anyone actually uses this.  I accidentally click on it several times a week, but I don't actually use it.  Anyone?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/06/19/look-up/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tip: Updates for Microsoft Office Excel 2007 Help</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/18/tip-updates-for-microsoft-office-excel-2007-help/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/06/18/tip-updates-for-microsoft-office-excel-2007-help/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 19:32:16 +0000</pubDate>
		<dc:creator>Ron de Bruin</dc:creator>
		
		<category><![CDATA[Excel12]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2597</guid>
		<description><![CDATA[Hi all
Today I talked about the search results from the Excel 2007 help (Offline) with a fellow MVP. Our results where different, my results were correct and useful but his results on the same search topic were useless. The reason why we have different search results is because that I have installed the help update [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all</p>
<p>Today I talked about the search results from the Excel 2007 help (Offline) with a fellow MVP. Our results where different, my results were correct and useful but his results on the same search topic were useless. The reason why we have different search results is because that I have installed the help update from 4/28/2009 that contains the latest revisions and additions to content in the Help files.</p>
<p><strong>Note</strong>: Search "<strong>Offline</strong>" give the best search results.</p>
<p>How do you change it to <strong>Offline </strong>if it is set to "<strong>Connected to Office Online</strong>" ?</p>
<p>Press<strong> F1</strong><br />
If you see "<strong>Connected to Office Online</strong>" in the bottom right corner then click on this<br />
and choose "<strong>Show content only from this computer</strong>"</p>
<p>I suggest that you install this update to get better search results when you search offline.<br />
You can get the updates through Microsoft Office update or download and install them by using the link below.<br />
Maybe you have it already installed ?</p>
<p><strong>Updates for Microsoft Office Excel 2007 Help</strong><br />
<a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2fbf47a2-e338-4ed8-92f2-b0a146e8593c&#038;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=2fbf47a2-e338-4ed8-92f2-b0a146e8593c&#038;displaylang=en</a></p>
<p><strong>Note</strong>: there are also updates for the other Office programs, see the links on the bottom of the page.</p>
<p>Regards Ron de Bruin<br />
<a href="http://www.rondebruin.nl/tips.htm">http://www.rondebruin.nl/tips.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/06/18/tip-updates-for-microsoft-office-excel-2007-help/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Entering Dates Into Cells Part II</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/18/entering-dates-into-cells-part-ii/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/06/18/entering-dates-into-cells-part-ii/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 16:16:41 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2594</guid>
		<description><![CDATA[I'm sure you all remember Entering Dates Into Cells from five years ago.  It was a simpler time.  Brittney Spears was telling us about her prerogative, the Olympics returned to Athens, and my date entering needs reflected the simplicity of the times.  Now I need more.
Here are some things I discovered about [...]]]></description>
			<content:encoded><![CDATA[<p>I'm sure you all remember <a href="http://www.dailydoseofexcel.com/archives/2004/04/30/entering-dates-into-cells/">Entering Dates Into Cells</a> from five years ago.  It was a simpler time.  Brittney Spears was telling us about her prerogative, the Olympics returned to Athens, and my date entering needs reflected the simplicity of the times.  Now I need more.</p>
<p>Here are some things I discovered about myself:</p>
<ul>
<li>I almost never need to enter the time into a cell</li>
<li>I don't need to continue editing the cell after I press Cntl+; to enter the date</li>
<li>I often have to enter yesterday or tomorrow</li>
</ul>
<p>Time to bloat <abbr title="Personal Macro Workbook">the PMW</abbr> again.  I'm going to take over the Control+; (control plus semicolon) shortcut and the Control+Shift+; shortcut.  The former will put the date into the activecell unless a date already exists there, in which case it will increment the date by one day.  The latter will do the same except that it will decrement the date by one day.</p>
<p>You know what's great about a video demonstrating keyboard shortcuts?  Anyway, here's what selecting C4, pressing Cntl+; three times, and pressing Cntl+Shift+; three times looks like:</p>
<p><object width="562" height="474"><param name="movie" value="http://content.screencast.com/users/dkusleika/folders/Jing/media/01ecae3d-7343-4db7-920b-0a7db3d609f9/jingswfplayer.swf"></param><param name="quality" value="high"></param><param name="bgcolor" value="#FFFFFF"></param><param name="flashVars" value="thumb=http://content.screencast.com/users/dkusleika/folders/Jing/media/01ecae3d-7343-4db7-920b-0a7db3d609f9/FirstFrame.jpg&#038;containerwidth=562&#038;containerheight=474&#038;loaderstyle=jing&#038;content=http://content.screencast.com/users/dkusleika/folders/Jing/media/01ecae3d-7343-4db7-920b-0a7db3d609f9/2009-06-18_1059.swf"></param><param name="allowFullScreen" value="true"></param><param name="scale" value="showall"></param><param name="allowScriptAccess" value="always"></param><param name="base" value="http://content.screencast.com/users/dkusleika/folders/Jing/media/01ecae3d-7343-4db7-920b-0a7db3d609f9/"></param>  <embed src="http://content.screencast.com/users/dkusleika/folders/Jing/media/01ecae3d-7343-4db7-920b-0a7db3d609f9/jingswfplayer.swf" quality="high" bgcolor="#FFFFFF" width="562" height="474" type="application/x-shockwave-flash" allowScriptAccess="always" flashVars="thumb=http://content.screencast.com/users/dkusleika/folders/Jing/media/01ecae3d-7343-4db7-920b-0a7db3d609f9/FirstFrame.jpg&#038;containerwidth=562&#038;containerheight=474&#038;loaderstyle=jing&#038;content=http://content.screencast.com/users/dkusleika/folders/Jing/media/01ecae3d-7343-4db7-920b-0a7db3d609f9/2009-06-18_1059.swf" allowFullScreen="true" base="http://content.screencast.com/users/dkusleika/folders/Jing/media/01ecae3d-7343-4db7-920b-0a7db3d609f9/" scale="showall"></embed></object></p>
<p>In my Auto_Open and Auto_Close macros, respectively, I have these OnKey assignments</p>
<div class="syntax_hilite">
<div id="vb-10">
<div class="vb">Application.OnKey <span style="color: #ff0000;">"^;"</span>, <span style="color: #ff0000;">"IncrementDate"</span><br />
Application.OnKey <span style="color: #ff0000;">"^+;"</span>, <span style="color: #ff0000;">"DecrementDate"</span></div>
</div>
</div>
<p></p>
<div class="syntax_hilite">
<div id="vb-11">
<div class="vb">Application.OnKey <span style="color: #ff0000;">"^;"</span><br />
Application.OnKey <span style="color: #ff0000;">"^+;"</span></div>
</div>
</div>
<p></p>
<p>I should have made the following all one macro, but I'm a little lazy like that.</p>
<div class="syntax_hilite">
<div id="vb-12">
<div class="vb"><span style="color: #0000DD;">Sub</span> IncrementDate<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">IsDate</span><span style="color:#008800;">&#40;</span>ActiveCell.Value<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ActiveCell.Value = ActiveCell.Value + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ActiveCell.Value = <span style="color: #0000DD;">Date</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ActiveCell.NumberFormat = <span style="color: #ff0000;">"m/d/yyyy"</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span><br />
&nbsp;<br />
<span style="color: #0000DD;">Sub</span> DecrementDate<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">IsDate</span><span style="color:#008800;">&#40;</span>ActiveCell.Value<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ActiveCell.Value = ActiveCell.Value - <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ActiveCell.Value = <span style="color: #0000DD;">Date</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ActiveCell.NumberFormat = <span style="color: #ff0000;">"m/d/yyyy"</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/06/18/entering-dates-into-cells-part-ii/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
