<?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: Looping Through Months</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 23:42:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Tushar Mehta</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37709</link>
		<dc:creator>Tushar Mehta</dc:creator>
		<pubDate>Tue, 03 Feb 2009 09:06:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37709</guid>
		<description>&lt;p&gt;It&#039;s kinda strange that no one used a data structure appropriate to the problem.  For some reason, people seem to have decided to limit themselves to existing loop control structures and functions and operators.&lt;/p&gt;
&lt;p&gt;To really do this correctly, introduce a structured data type that includes the year and the month.  Add functions to support transfers to/from &quot;real dates&quot; as well as a &quot;next month&quot; function.  One could also go all out and use a class module to create an appropriate type.&lt;/p&gt;
&lt;p&gt;Realizing that I could &quot;embed&quot; the new data structure in an existing data type, I decided to be somewhat lazy.  So, my &quot;data structure&quot; consists of YYYYMM embedded in a Long data type.&lt;/p&gt;
&lt;p&gt;I need two functions, one to map a date to YYYYMM and another to return the next month&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; YYYYMM(aDate &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;)&lt;br&gt;
&#160; &#160; YYYYMM = Year(aDate) * 100 + Month(aDate)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt; NextYYYYMM(YYYYMM &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; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; YYYYMM &lt;span class=&quot;kw1&quot;&gt;Mod&lt;/span&gt; 100 = 12 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; NextYYYYMM = YYYYMM + 100 - 11 _&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt; NextYYYYMM = YYYYMM + 1&lt;br&gt;
&#160; &#160; &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;Now, the code to implement Dick&#039;s requirement is relatively trivial&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; MonthLoop()&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; CurrYM &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;, LimYM &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; &#160; CurrYM = YYYYMM(#10/1/2007#)&lt;br&gt;
&#160; &#160; LimYM = YYYYMM(#9/30/2008#)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Do&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;While&lt;/span&gt; CurrYM &lt; = LimYM&lt;br&gt;
&#160; &#160; &#160; &#160; Debug.&lt;span class=&quot;kw1&quot;&gt;Print&lt;/span&gt; CurrYM&lt;br&gt;
&#160; &#160; &#160; &#160; CurrYM = NextYYYYMM(CurrYM)&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Loop&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;Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;One can also use the DateSerial function to implement the above...kind of.  Neither KeepItCool nor Jon pointed out a potential pitfall with DateSerial.  If a date doesn&#039;t exist in a particular month, it will pick a date in the *next* month.  So, if the current date is 31 Jan 2008, then 1 month out will be a date in March!  Nonetheless, I had thought of using it in this case as below.&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; MonthsDiff(aDate &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;, &lt;span class=&quot;kw1&quot;&gt;Optional&lt;/span&gt; NbrMths &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt; = 1)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;co1&quot;&gt;&#039;It is the caller&#039;s responsibility to ensure that _&lt;br&gt;
&#160; &#160; &#160;the day-of-month is meaningful in the desired month!&lt;br&gt;
&lt;/span&gt; &#160; &#160;MonthsDiff DateSerial(Year(aDate), Month(aDate) + NbrMths, Day(aDate))&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; MonthLoop1()&lt;br&gt;
&#160; &#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;Date&lt;/span&gt;&lt;br&gt;
&#160; &#160; I = #10/1/2007#&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Do&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;While&lt;/span&gt; I &lt; = #9/30/2008#&lt;br&gt;
&#160; &#160; &#160; &#160; Debug.&lt;span class=&quot;kw1&quot;&gt;Print&lt;/span&gt; I&lt;br&gt;
&#160; &#160; &#160; &#160; I = MonthsDiff(I)&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Loop&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;Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>It&#8217;s kinda strange that no one used a data structure appropriate to the problem.  For some reason, people seem to have decided to limit themselves to existing loop control structures and functions and operators.</p>
<p>To really do this correctly, introduce a structured data type that includes the year and the month.  Add functions to support transfers to/from &#8220;real dates&#8221; as well as a &#8220;next month&#8221; function.  One could also go all out and use a class module to create an appropriate type.</p>
<p>Realizing that I could &#8220;embed&#8221; the new data structure in an existing data type, I decided to be somewhat lazy.  So, my &#8220;data structure&#8221; consists of YYYYMM embedded in a Long data type.</p>
<p>I need two functions, one to map a date to YYYYMM and another to return the next month</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> YYYYMM(aDate <span class="kw1">As</span> <span class="kw1">Date</span>)<br />
&nbsp; &nbsp; YYYYMM = Year(aDate) * 100 + Month(aDate)<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">Function</span><br />
<span class="kw1">Function</span> NextYYYYMM(YYYYMM <span class="kw1">As</span> <span class="kw1">Long</span>)<br />
&nbsp; &nbsp; <span class="kw1">If</span> YYYYMM <span class="kw1">Mod</span> 100 = 12 <span class="kw1">Then</span> NextYYYYMM = YYYYMM + 100 &#8211; 11 _<br />
&nbsp; &nbsp; <span class="kw1">Else</span> NextYYYYMM = YYYYMM + 1<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">Function</span></div>
</div>
<p>Now, the code to implement Dick&#8217;s requirement is relatively trivial</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Sub</span> MonthLoop()<br />
&nbsp; &nbsp; <span class="kw1">Dim</span> CurrYM <span class="kw1">As</span> <span class="kw1">Long</span>, LimYM <span class="kw1">As</span> <span class="kw1">Long</span><br />
&nbsp; &nbsp; CurrYM = YYYYMM(#10/1/2007#)<br />
&nbsp; &nbsp; LimYM = YYYYMM(#9/30/2008#)<br />
&nbsp; &nbsp; <span class="kw1">Do</span> <span class="kw1">While</span> CurrYM &lt; = LimYM<br />
&nbsp; &nbsp; &nbsp; &nbsp; Debug.<span class="kw1">Print</span> CurrYM<br />
&nbsp; &nbsp; &nbsp; &nbsp; CurrYM = NextYYYYMM(CurrYM)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Loop</span><br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">Sub</span></div>
</div>
<p>One can also use the DateSerial function to implement the above&#8230;kind of.  Neither KeepItCool nor Jon pointed out a potential pitfall with DateSerial.  If a date doesn&#8217;t exist in a particular month, it will pick a date in the *next* month.  So, if the current date is 31 Jan 2008, then 1 month out will be a date in March!  Nonetheless, I had thought of using it in this case as below.</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> MonthsDiff(aDate <span class="kw1">As</span> <span class="kw1">Date</span>, <span class="kw1">Optional</span> NbrMths <span class="kw1">As</span> <span class="kw1">Integer</span> = 1)<br />
&nbsp; &nbsp; <span class="co1">&#8216;It is the caller&#8217;s responsibility to ensure that _<br />
&nbsp; &nbsp; &nbsp;the day-of-month is meaningful in the desired month!<br />
</span> &nbsp; &nbsp;MonthsDiff DateSerial(Year(aDate), Month(aDate) + NbrMths, Day(aDate))<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">Function</span><br />
<span class="kw1">Sub</span> MonthLoop1()<br />
&nbsp; &nbsp; <span class="kw1">Dim</span> I <span class="kw1">As</span> <span class="kw1">Date</span><br />
&nbsp; &nbsp; I = #10/1/2007#<br />
&nbsp; &nbsp; <span class="kw1">Do</span> <span class="kw1">While</span> I &lt; = #9/30/2008#<br />
&nbsp; &nbsp; &nbsp; &nbsp; Debug.<span class="kw1">Print</span> I<br />
&nbsp; &nbsp; &nbsp; &nbsp; I = MonthsDiff(I)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Loop</span><br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">Sub</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Maxey</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37698</link>
		<dc:creator>Dan Maxey</dc:creator>
		<pubDate>Mon, 02 Feb 2009 21:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37698</guid>
		<description>&lt;p&gt;Usually I&#039;m the one on the soapbox about elegant code, but gosh... is it really worth the effort on this one?  Here is my 2 minute &quot;beat it with a rock until it goes away&quot; solution.&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; loopmonths()&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; startdate &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; enddate &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; startmonth &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;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; numberofmonths &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;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; firstmonth &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;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; count &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;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; thatmonth &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;
&lt;br&gt;
&#160; startdate = Now&lt;br&gt;
&#160; enddate = startdate + 730 &lt;span class=&quot;co1&quot;&gt;&#039;this example is two years from now, but any future date will do&lt;br&gt;
&lt;/span&gt; &#160;&lt;br&gt;
&#160; numberofmonths = DateDiff(&lt;span class=&quot;st0&quot;&gt;&quot;m&quot;&lt;/span&gt;, startdate, enddate)&lt;br&gt;
&#160; firstmonth = DatePart(&lt;span class=&quot;st0&quot;&gt;&quot;m&quot;&lt;/span&gt;, startdate)&lt;br&gt;
&#160; thatmonth = firstmonth&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; count = 1 &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; numberofmonths&lt;br&gt;
&#160; &#160; Debug.&lt;span class=&quot;kw1&quot;&gt;Print&lt;/span&gt; thatmonth &#160;&lt;span class=&quot;co1&quot;&gt;&#039;Here is where your &quot;do stuff&quot; goes&lt;br&gt;
&lt;/span&gt; &#160; &#160;thatmonth = thatmonth + 1&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; thatmonth &gt; 12 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; thatmonth = 1&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Next&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;Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>Usually I&#8217;m the one on the soapbox about elegant code, but gosh&#8230; is it really worth the effort on this one?  Here is my 2 minute &#8220;beat it with a rock until it goes away&#8221; solution.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Sub</span> loopmonths()</p>
<p><span class="kw1">Dim</span> startdate <span class="kw1">As</span> <span class="kw1">Date</span><br />
<span class="kw1">Dim</span> enddate <span class="kw1">As</span> <span class="kw1">Date</span><br />
<span class="kw1">Dim</span> startmonth <span class="kw1">As</span> <span class="kw1">Long</span><br />
<span class="kw1">Dim</span> numberofmonths <span class="kw1">As</span> <span class="kw1">Long</span><br />
<span class="kw1">Dim</span> firstmonth <span class="kw1">As</span> <span class="kw1">Long</span><br />
<span class="kw1">Dim</span> count <span class="kw1">As</span> <span class="kw1">Long</span><br />
<span class="kw1">Dim</span> thatmonth <span class="kw1">As</span> <span class="kw1">Long</span></p>
<p>&nbsp; startdate = Now<br />
&nbsp; enddate = startdate + 730 <span class="co1">&#8216;this example is two years from now, but any future date will do<br />
</span> &nbsp;<br />
&nbsp; numberofmonths = DateDiff(<span class="st0">&#8220;m&#8221;</span>, startdate, enddate)<br />
&nbsp; firstmonth = DatePart(<span class="st0">&#8220;m&#8221;</span>, startdate)<br />
&nbsp; thatmonth = firstmonth<br />
&nbsp; <span class="kw1">For</span> count = 1 <span class="kw1">To</span> numberofmonths<br />
&nbsp; &nbsp; Debug.<span class="kw1">Print</span> thatmonth &nbsp;<span class="co1">&#8216;Here is where your &#8220;do stuff&#8221; goes<br />
</span> &nbsp; &nbsp;thatmonth = thatmonth + 1<br />
&nbsp; &nbsp; <span class="kw1">If</span> thatmonth &amp;gt; 12 <span class="kw1">Then</span> thatmonth = 1<br />
&nbsp; <span class="kw1">Next</span></p>
<p><span class="kw1">End</span> <span class="kw1">Sub</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37696</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Mon, 02 Feb 2009 19:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37696</guid>
		<description>&lt;p&gt;so, i lied. I really need to not try to do this so quickly. I made a mistake in my assignment to nMonth. In order the advance the sequence the second line of code inside the loop should be below.&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;nMonth = ((nMonth &lt;span class=&quot;kw1&quot;&gt;mod&lt;/span&gt; 12) +1)&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>so, i lied. I really need to not try to do this so quickly. I made a mistake in my assignment to nMonth. In order the advance the sequence the second line of code inside the loop should be below.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer">nMonth = ((nMonth <span class="kw1">mod</span> 12) +1)</div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37695</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Mon, 02 Feb 2009 19:07:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37695</guid>
		<description>&lt;p&gt;okay, last edit I promise. Change the while loop to a do..until loop and you&#039;re money.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>okay, last edit I promise. Change the while loop to a do..until loop and you&#8217;re money.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37694</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Mon, 02 Feb 2009 18:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37694</guid>
		<description>&lt;p&gt;My solution assumes that you will not be looping through more than 1 year. Sorry for the repost, but apparently I must use != do indicate not equals when posting&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; loopMonths&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; dtStartDate &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;, dtEndDate &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;&lt;br&gt;
&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;variant&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; nMonth &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
dtStartDate =#10/1/2007#: dtEndDate = #9/30/2008#&lt;br&gt;
&lt;br&gt;
nMonth = month(dtStartDate)&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; nMonth != month(dtEndDate)&lt;br&gt;
&#160; &#160;x=CallFunction(nMonth)&lt;br&gt;
&#160; &#160;nMonth = ((nMonth -1) &lt;span class=&quot;kw1&quot;&gt;mod&lt;/span&gt; 12) +1&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Loop&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;sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>My solution assumes that you will not be looping through more than 1 year. Sorry for the repost, but apparently I must use != do indicate not equals when posting</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Sub</span> loopMonths<br />
<span class="kw1">Dim</span> dtStartDate <span class="kw1">as</span> <span class="kw1">Date</span>, dtEndDate <span class="kw1">as</span> <span class="kw1">Date</span><br />
<span class="kw1">Dim</span> x <span class="kw1">as</span> <span class="kw1">variant</span><br />
<span class="kw1">Dim</span> nMonth <span class="kw1">as</span> <span class="kw1">Integer</span></p>
<p>dtStartDate =#10/1/2007#: dtEndDate = #9/30/2008#</p>
<p>nMonth = month(dtStartDate)<br />
<span class="kw1">do</span> <span class="kw1">while</span> nMonth != month(dtEndDate)<br />
&nbsp; &nbsp;x=CallFunction(nMonth)<br />
&nbsp; &nbsp;nMonth = ((nMonth -1) <span class="kw1">mod</span> 12) +1<br />
<span class="kw1">Loop</span></p>
<p><span class="kw1">end</span> <span class="kw1">sub</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37693</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Mon, 02 Feb 2009 18:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37693</guid>
		<description>&lt;p&gt;My solution assumes that you will not be looping through more than 1 year&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; loopMonths&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; dtStartDate &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;, dtEndDate &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;&lt;br&gt;
&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;variant&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; nMonth &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
dtStartDate =#10/1/2007#: dtEndDate = #9/30/2008#&lt;br&gt;
&lt;br&gt;
nMonth = month(dtStartDate)&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; nMonth &#160;month(dtEndDate)&lt;br&gt;
&#160; &#160;x=CallFunction(nMonth)&lt;br&gt;
&#160; &#160;nMonth = ((nMonth -1) &lt;span class=&quot;kw1&quot;&gt;mod&lt;/span&gt; 12) +1&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Loop&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;sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>My solution assumes that you will not be looping through more than 1 year</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Sub</span> loopMonths</p>
<p><span class="kw1">Dim</span> dtStartDate <span class="kw1">as</span> <span class="kw1">Date</span>, dtEndDate <span class="kw1">as</span> <span class="kw1">Date</span><br />
<span class="kw1">Dim</span> x <span class="kw1">as</span> <span class="kw1">variant</span><br />
<span class="kw1">Dim</span> nMonth <span class="kw1">as</span> <span class="kw1">Integer</span></p>
<p>dtStartDate =#10/1/2007#: dtEndDate = #9/30/2008#</p>
<p>nMonth = month(dtStartDate)<br />
<span class="kw1">do</span> <span class="kw1">while</span> nMonth &nbsp;month(dtEndDate)<br />
&nbsp; &nbsp;x=CallFunction(nMonth)<br />
&nbsp; &nbsp;nMonth = ((nMonth -1) <span class="kw1">mod</span> 12) +1<br />
<span class="kw1">Loop</span></p>
<p><span class="kw1">end</span> <span class="kw1">sub</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Orlando</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37669</link>
		<dc:creator>Orlando</dc:creator>
		<pubDate>Mon, 02 Feb 2009 00:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37669</guid>
		<description>&lt;p&gt;Sub LoopMonths()&lt;/p&gt;
&lt;p&gt;    Dim i As Date&lt;br&gt;
    Dim dtStartDate As Date, dtEndDate As Date&lt;br&gt;
    Dim x As Variant&lt;/p&gt;
&lt;p&gt;    dtStartDate = #10/1/2007#: dtEndDate = #9/30/2008#&lt;br&gt;
    i = dtStartDate&lt;br&gt;
    Do&lt;br&gt;
            x = CallFunction(Month(i))&lt;br&gt;
            i = DateSerial(Year(i), Month(i) + 1, 1)&lt;br&gt;
    Loop While i &lt;= dtEndDate&lt;/p&gt;
&lt;p&gt;End Sub&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Sub LoopMonths()</p>
<p>    Dim i As Date<br />
    Dim dtStartDate As Date, dtEndDate As Date<br />
    Dim x As Variant</p>
<p>    dtStartDate = #10/1/2007#: dtEndDate = #9/30/2008#<br />
    i = dtStartDate<br />
    Do<br />
            x = CallFunction(Month(i))<br />
            i = DateSerial(Year(i), Month(i) + 1, 1)<br />
    Loop While i &lt;= dtEndDate</p>
<p>End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Akers</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37658</link>
		<dc:creator>Chris Akers</dc:creator>
		<pubDate>Sun, 01 Feb 2009 21:29:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37658</guid>
		<description>&lt;p&gt;Makes handy use of DateSerial normalizing date parts that are out-of-range:&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; LoopMonths()&lt;br&gt;
&#160; &#160;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; intYear &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;, intMonth &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;, i &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; dtStartDate &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;, dtEndDate &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;, dtLoopDate &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;&lt;br&gt;
&#160; &#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;Variant&lt;/span&gt;&lt;br&gt;
&#160; &#160;&lt;br&gt;
&#160; &#160; dtStartDate = #10/1/2007#: dtEndDate = #9/30/2008#&lt;br&gt;
&#160; &#160; intYear = Year(dtStartDate): intMonth = Month(dtStartDate)&lt;br&gt;
&#160; &#160; dtLoopDate = dtStartDate: i = 0&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Do&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; x = CallFunction(Month(dtLoopDate))&lt;br&gt;
&#160; &#160; &#160; &#160; i = i + 1&lt;br&gt;
&#160; &#160; &#160; &#160; dtLoopDate = DateSerial(intYear, intMonth + i, 1)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Loop&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;While&lt;/span&gt; dtLoopDate &lt;= dtEndDate&lt;br&gt;
&#160; &#160;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>Makes handy use of DateSerial normalizing date parts that are out-of-range:</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Sub</span> LoopMonths()<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span class="kw1">Dim</span> intYear <span class="kw1">As</span> <span class="kw1">Integer</span>, intMonth <span class="kw1">As</span> <span class="kw1">Integer</span>, i <span class="kw1">As</span> <span class="kw1">Integer</span><br />
&nbsp; &nbsp; <span class="kw1">Dim</span> dtStartDate <span class="kw1">As</span> <span class="kw1">Date</span>, dtEndDate <span class="kw1">As</span> <span class="kw1">Date</span>, dtLoopDate <span class="kw1">As</span> <span class="kw1">Date</span><br />
&nbsp; &nbsp; <span class="kw1">Dim</span> x <span class="kw1">As</span> <span class="kw1">Variant</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; dtStartDate = #10/1/2007#: dtEndDate = #9/30/2008#<br />
&nbsp; &nbsp; intYear = Year(dtStartDate): intMonth = Month(dtStartDate)<br />
&nbsp; &nbsp; dtLoopDate = dtStartDate: i = 0<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">Do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; x = CallFunction(Month(dtLoopDate))<br />
&nbsp; &nbsp; &nbsp; &nbsp; i = i + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; dtLoopDate = DateSerial(intYear, intMonth + i, 1)<br />
&nbsp; &nbsp; <span class="kw1">Loop</span> <span class="kw1">While</span> dtLoopDate &amp;lt;= dtEndDate<br />
&nbsp; &nbsp;<br />
<span class="kw1">End</span> <span class="kw1">Sub</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37657</link>
		<dc:creator>Nigel</dc:creator>
		<pubDate>Sun, 01 Feb 2009 19:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37657</guid>
		<description>&lt;p&gt;Annoyingly, the &#039;not equals&#039; sign &lt;&amp;GT  in the branching statement iMonth (not equals) iPrevious isn&#039;t rendered by the VB formatter.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Annoyingly, the &#8216;not equals&#8217; sign &lt;&amp;GT  in the branching statement iMonth (not equals) iPrevious isn&#8217;t rendered by the VB formatter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/31/looping-through-months/#comment-37656</link>
		<dc:creator>Nigel</dc:creator>
		<pubDate>Sun, 01 Feb 2009 19:52:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1989#comment-37656</guid>
		<description>&lt;p&gt;Hmmm... Depends what you&#039;re trying to do with the code: list every month included between dtStartDate and dtEndDate?&lt;/p&gt;
&lt;p&gt;That&#039;s got some complications: anything that uses DateAdd - either explicitly, or implied in a modulo division - runs into the bug that adding a month to the last day of February lands you on the 28th (or 29th) of March instead of the last day of March. Ditto for any month 30 days in length followed by one of 31 days. The workaround of hopping back one day from the first of the month is inelegant and needs a lot of coding.&lt;/p&gt;
&lt;p&gt;Bluntly, I don&#039;t think there&#039;s any escape from the need to loop through each and every day between dtStartDate and dtEndDate. Not without a truly horrible perversion of the loop structure and rather kludgy &#039;magic number&#039;:&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; LoopMonths()&lt;br&gt;
&#160; &#160;&lt;br&gt;
&#160; &#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;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; dtStartDate &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;, dtEndDate &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Date&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; iMonth &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;, iPrevious &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160;&lt;br&gt;
&#160; &#160; dtStartDate = &lt;span class=&quot;st0&quot;&gt;&quot;5 Oct 2007&quot;&lt;/span&gt;&lt;br&gt;
&#160; &#160; dtEndDate = &lt;span class=&quot;st0&quot;&gt;&quot;21 Sept 2008&quot;&lt;/span&gt;&lt;br&gt;
&#160; &#160;&lt;br&gt;
&#160; &#160; iPrevious = VBA.Month(dtStartDate)&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; Debug.&lt;span class=&quot;kw1&quot;&gt;Print&lt;/span&gt; iPrevious&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; i = dtStartDate &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; dtEndDate&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; iMonth = VBA.Month(i)&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; iMonth &#160;iPrevious &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160;iPrevious = VBA.Month(i)&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160;Debug.&lt;span class=&quot;kw1&quot;&gt;Print&lt;/span&gt; iPrevious&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160;i = i + 27 &#160; &lt;span class=&quot;co1&quot;&gt;&#039;skip unnecessary iterations&lt;br&gt;
&lt;/span&gt; &#160; &#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; &#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt; i&lt;br&gt;
&#160; &#160;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>Hmmm&#8230; Depends what you&#8217;re trying to do with the code: list every month included between dtStartDate and dtEndDate?</p>
<p>That&#8217;s got some complications: anything that uses DateAdd &#8211; either explicitly, or implied in a modulo division &#8211; runs into the bug that adding a month to the last day of February lands you on the 28th (or 29th) of March instead of the last day of March. Ditto for any month 30 days in length followed by one of 31 days. The workaround of hopping back one day from the first of the month is inelegant and needs a lot of coding.</p>
<p>Bluntly, I don&#8217;t think there&#8217;s any escape from the need to loop through each and every day between dtStartDate and dtEndDate. Not without a truly horrible perversion of the loop structure and rather kludgy &#8216;magic number&#8217;:</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Sub</span> LoopMonths()<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span class="kw1">Dim</span> i <span class="kw1">As</span> <span class="kw1">Long</span><br />
&nbsp; &nbsp; <span class="kw1">Dim</span> dtStartDate <span class="kw1">As</span> <span class="kw1">Date</span>, dtEndDate <span class="kw1">As</span> <span class="kw1">Date</span><br />
&nbsp; &nbsp; <span class="kw1">Dim</span> iMonth <span class="kw1">As</span> <span class="kw1">Integer</span>, iPrevious <span class="kw1">As</span> <span class="kw1">Integer</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; dtStartDate = <span class="st0">&#8220;5 Oct 2007&#8243;</span><br />
&nbsp; &nbsp; dtEndDate = <span class="st0">&#8220;21 Sept 2008&#8243;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; iPrevious = VBA.Month(dtStartDate)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Debug.<span class="kw1">Print</span> iPrevious<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">For</span> i = dtStartDate <span class="kw1">To</span> dtEndDate<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; iMonth = VBA.Month(i)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">If</span> iMonth &nbsp;iPrevious <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iPrevious = VBA.Month(i)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Debug.<span class="kw1">Print</span> iPrevious<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i = i + 27 &nbsp; <span class="co1">&#8216;skip unnecessary iterations<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">Next</span> i<br />
&nbsp; &nbsp;<br />
<span class="kw1">End</span> <span class="kw1">Sub</span></div>
</div>
]]></content:encoded>
	</item>
</channel>
</rss>

