<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/"
	>
<channel>
	<title>Comments on: Go Sub,  to go?</title>
	<atom:link href="http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/</link>
	<description></description>
	<lastBuildDate>Tue,  7 Feb 2012 08:09:02 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	<item>
		<title>By: ross</title>
		<link>http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/comment-page-1/#comment-72</link>
		<dc:creator>ross</dc:creator>
		<pubDate>Mon, 27 Mar 2006 09:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/#comment-72</guid>
		<description>thanks John, Sorry that the code is not very well displayed, when time permits i will look into it ;-)</description>
		<content:encoded><![CDATA[<p>thanks John, Sorry that the code is not very well displayed, when time permits i will look into it ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Skewes</title>
		<link>http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/comment-page-1/#comment-68</link>
		<dc:creator>John Skewes</dc:creator>
		<pubDate>Fri, 24 Mar 2006 04:49:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/#comment-68</guid>
		<description>Hi Ross,

Yes, not to mention the static vars... Gosub and Return was used in a lot of earlier programming languages, notably BASIC (&lt;em&gt;the grandfather of VBA&lt;/em&gt;). 

You can have as many Gosub/Returns as you like in a procedure but its use has largely declined due to the propensity for novice programmers to use it in a loose unstructered manner, with GoSubs and Returns popping up everywhere in the main body of code. It then becomes difficult to follow the flow of the code. 

Never-the-less, it can be handy occasionally &lt;strong&gt;as long as it&#039;s kept structured and not &#039;overdone&#039;&lt;/strong&gt;. I&#039;ve updated the example on my site to show the difference, here it is (&lt;em&gt;I don&#039;t know if the code tags will show properly here&lt;/em&gt;)

---------------------------------------------------------------------------------

A simple example use of Gosub and Return...


[VBA]Sub CopyRows_UseGosub()

      Dim Cell As Range, TargetSheet As String

      With Sheets(&quot;Sheet1&quot;)
            For Each Cell In .Range(&quot;A2&quot;, .Range(&quot;A&quot; &amp; Rows.Count).End(xlUp))
                  Select Case Cell.Offset(0, 4)
                  Case &quot;Match&quot;
                        TargetSheet = &quot;Sheet2&quot;: GoSub DoCopy
                  Case &quot;No Match&quot;
                        TargetSheet = &quot;Sheet3&quot;: GoSub DoCopy
                  Case &quot;Part Match&quot;
                        TargetSheet = &quot;Sheet4&quot;: GoSub DoCopy
                  Case &quot;Negative Match&quot;
                        TargetSheet = &quot;Sheet5&quot;: GoSub DoCopy
                  Case Else
                        TargetSheet = &quot;Sheet6&quot;: GoSub DoCopy
                  End Select
            Next
            Exit Sub

DoCopy:
            .Range(Cell.Address, Cell.Offset(0, 2)).Copy _
                        Sheets(TargetSheet).Range(&quot;A&quot; &amp; Rows.Count) _
                        .End(xlUp).Offset(1, 0)
            Return

      End With
End Sub[/VBA]


As a comparison, the alternative code below to accomplish exactly the same task is &#039;wordier&#039;, more obscure for a coder to &#039;read&#039;, and it&#039;s difficult to ascertain the differences for each case (&lt;em&gt;the only differences being the sheets name&lt;/em&gt; :))


[VBA]Sub CopyRows_NoGosub()

      Dim Cell As Range

      With Sheets(&quot;Sheet1&quot;)
            For Each Cell In .Range(&quot;A2&quot;, .Range(&quot;A&quot; &amp; Rows.Count).End(xlUp))
                  Select Case Cell.Offset(0, 4)
                  Case &quot;Match&quot;
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _
                                    Sheets(&quot;Sheet2&quot;).Range(&quot;A&quot; &amp; Rows.Count) _
                                    .End(xlUp).Offset(1, 0)
                  Case &quot;No Match&quot;
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _
                                    Sheets(&quot;Sheet3&quot;).Range(&quot;A&quot; &amp; Rows.Count) _
                                    .End(xlUp).Offset(1, 0)
                  Case &quot;Part Match&quot;
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _
                                    Sheets(&quot;Sheet4&quot;).Range(&quot;A&quot; &amp; Rows.Count) _
                                    .End(xlUp).Offset(1, 0)
                  Case &quot;Negative Match&quot;
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _
                                    Sheets(&quot;Sheet5&quot;).Range(&quot;A&quot; &amp; Rows.Count) _
                                    .End(xlUp).Offset(1, 0)
                  Case Else
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _
                                    Sheets(&quot;Sheet6&quot;).Range(&quot;A&quot; &amp; Rows.Count) _
                                    .End(xlUp).Offset(1, 0)
                  End Select
            Next
      End With
      
End Sub[/VBA]</description>
		<content:encoded><![CDATA[<p>Hi Ross,</p>
<p>Yes, not to mention the static vars&#8230; Gosub and Return was used in a lot of earlier programming languages, notably BASIC (<em>the grandfather of VBA</em>). </p>
<p>You can have as many Gosub/Returns as you like in a procedure but its use has largely declined due to the propensity for novice programmers to use it in a loose unstructered manner, with GoSubs and Returns popping up everywhere in the main body of code. It then becomes difficult to follow the flow of the code. </p>
<p>Never-the-less, it can be handy occasionally <strong>as long as it&#8217;s kept structured and not &#8216;overdone&#8217;</strong>. I&#8217;ve updated the example on my site to show the difference, here it is (<em>I don&#8217;t know if the code tags will show properly here</em>)</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>A simple example use of Gosub and Return&#8230;</p>
<p>[VBA]Sub CopyRows_UseGosub()</p>
<p>      Dim Cell As Range, TargetSheet As String</p>
<p>      With Sheets(&#8220;Sheet1&#8243;)<br />
            For Each Cell In .Range(&#8220;A2&#8243;, .Range(&#8220;A&#8221; &amp; Rows.Count).End(xlUp))<br />
                  Select Case Cell.Offset(0, 4)<br />
                  Case &#8220;Match&#8221;<br />
                        TargetSheet = &#8220;Sheet2&#8243;: GoSub DoCopy<br />
                  Case &#8220;No Match&#8221;<br />
                        TargetSheet = &#8220;Sheet3&#8243;: GoSub DoCopy<br />
                  Case &#8220;Part Match&#8221;<br />
                        TargetSheet = &#8220;Sheet4&#8243;: GoSub DoCopy<br />
                  Case &#8220;Negative Match&#8221;<br />
                        TargetSheet = &#8220;Sheet5&#8243;: GoSub DoCopy<br />
                  Case Else<br />
                        TargetSheet = &#8220;Sheet6&#8243;: GoSub DoCopy<br />
                  End Select<br />
            Next<br />
            Exit Sub</p>
<p>DoCopy:<br />
            .Range(Cell.Address, Cell.Offset(0, 2)).Copy _<br />
                        Sheets(TargetSheet).Range(&#8220;A&#8221; &amp; Rows.Count) _<br />
                        .End(xlUp).Offset(1, 0)<br />
            Return</p>
<p>      End With<br />
End Sub[/VBA]</p>
<p>As a comparison, the alternative code below to accomplish exactly the same task is &#8216;wordier&#8217;, more obscure for a coder to &#8216;read&#8217;, and it&#8217;s difficult to ascertain the differences for each case (<em>the only differences being the sheets name</em> :))</p>
<p>[VBA]Sub CopyRows_NoGosub()</p>
<p>      Dim Cell As Range</p>
<p>      With Sheets(&#8220;Sheet1&#8243;)<br />
            For Each Cell In .Range(&#8220;A2&#8243;, .Range(&#8220;A&#8221; &amp; Rows.Count).End(xlUp))<br />
                  Select Case Cell.Offset(0, 4)<br />
                  Case &#8220;Match&#8221;<br />
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _<br />
                                    Sheets(&#8220;Sheet2&#8243;).Range(&#8220;A&#8221; &amp; Rows.Count) _<br />
                                    .End(xlUp).Offset(1, 0)<br />
                  Case &#8220;No Match&#8221;<br />
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _<br />
                                    Sheets(&#8220;Sheet3&#8243;).Range(&#8220;A&#8221; &amp; Rows.Count) _<br />
                                    .End(xlUp).Offset(1, 0)<br />
                  Case &#8220;Part Match&#8221;<br />
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _<br />
                                    Sheets(&#8220;Sheet4&#8243;).Range(&#8220;A&#8221; &amp; Rows.Count) _<br />
                                    .End(xlUp).Offset(1, 0)<br />
                  Case &#8220;Negative Match&#8221;<br />
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _<br />
                                    Sheets(&#8220;Sheet5&#8243;).Range(&#8220;A&#8221; &amp; Rows.Count) _<br />
                                    .End(xlUp).Offset(1, 0)<br />
                  Case Else<br />
                        .Range(Cell.Address, Cell.Offset(0, 2)).Copy _<br />
                                    Sheets(&#8220;Sheet6&#8243;).Range(&#8220;A&#8221; &amp; Rows.Count) _<br />
                                    .End(xlUp).Offset(1, 0)<br />
                  End Select<br />
            Next<br />
      End With</p>
<p>End Sub[/VBA]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ross</title>
		<link>http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/comment-page-1/#comment-65</link>
		<dc:creator>ross</dc:creator>
		<pubDate>Tue, 21 Mar 2006 11:29:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/#comment-65</guid>
		<description>Not to mention the static var dec too John - it&#039;s a stange one, but it guess it just another tool like toy say.</description>
		<content:encoded><![CDATA[<p>Not to mention the static var dec too John &#8211; it&#8217;s a stange one, but it guess it just another tool like toy say.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Skewes</title>
		<link>http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/comment-page-1/#comment-62</link>
		<dc:creator>John Skewes</dc:creator>
		<pubDate>Tue, 21 Mar 2006 03:07:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.methodsinexcel.co.uk/2006/02/15/go-sub-to-go/#comment-62</guid>
		<description>Hi Ross,

Yes, I usually would do the same, but it&#039;s useful when you may have (&lt;em&gt;say&lt;/em&gt;) lots of variables that you don&#039;t want to declare as public (&lt;em&gt;but then a function would probably be the way to go&lt;/em&gt;) anyway, it&#039;s another choice that&#039;s always available in our bag of tricks.

Regards,
John :)</description>
		<content:encoded><![CDATA[<p>Hi Ross,</p>
<p>Yes, I usually would do the same, but it&#8217;s useful when you may have (<em>say</em>) lots of variables that you don&#8217;t want to declare as public (<em>but then a function would probably be the way to go</em>) anyway, it&#8217;s another choice that&#8217;s always available in our bag of tricks.</p>
<p>Regards,<br />
John :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

