<?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: Beginning VBA: Your First Function</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Tue, 07 Feb 2012 23:32:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Doug Jenkins</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-28014</link>
		<dc:creator>Doug Jenkins</dc:creator>
		<pubDate>Fri, 12 Oct 2007 01:07:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-28014</guid>
		<description>&lt;p&gt;&quot;Jeffrey: Since x is already a range, you&#039;d use&lt;/p&gt;
&lt;p&gt;ReadCell = x.Value&quot;&lt;/p&gt;
&lt;p&gt;Or just declare it as a double (or whatever it is) rather than a range:&lt;/p&gt;
&lt;p&gt;If x is a single cell:&lt;/p&gt;
&lt;p&gt;ReadCell(x As Double)&lt;br&gt;
ReadCell = x&lt;br&gt;
End Function&lt;/p&gt;
&lt;p&gt;Or if x is a multicell range, declare it as a Variant:&lt;/p&gt;
&lt;p&gt;ReadCell(x As Variant)&lt;br&gt;
&#039; This line converts x from a range object into an array, it speeds things up hugely!&lt;br&gt;
x = x.value&lt;br&gt;
&#039; Then read whichever value you want from the array&lt;br&gt;
ReadCell = x(1,1)&lt;br&gt;
End Function&lt;/p&gt;
&lt;p&gt;&quot;As far as I know, I&#039;ve never written a function that I&#039;ve used in a cell AND called from a Sub procedure. It&#039;s usually one or the other.&quot;&lt;/p&gt;
&lt;p&gt;I do that all the time.  Like this:&lt;/p&gt;
&lt;p&gt;Function RtoP(Coords As Variant, Optional Origin As Variant, Optional Result As Long) As Variant&lt;br&gt;
    Dim ...&lt;/p&gt;
&lt;p&gt;    If TypeName(Coords) = &quot;Range&quot; Then&lt;br&gt;
        Coords = Coords.Value&lt;br&gt;
    End If&lt;br&gt;
    ....&lt;/p&gt;
&lt;p&gt;So if the function is called from a worksheet, and Coords is a range, it gets converted into an array.  If it is called from a sub it will usually be an array already, but if it isn&#039;t it gets converted.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>&#8220;Jeffrey: Since x is already a range, you&#8217;d use</p>
<p>ReadCell = x.Value&#8221;</p>
<p>Or just declare it as a double (or whatever it is) rather than a range:</p>
<p>If x is a single cell:</p>
<p>ReadCell(x As Double)<br />
ReadCell = x<br />
End Function</p>
<p>Or if x is a multicell range, declare it as a Variant:</p>
<p>ReadCell(x As Variant)<br />
&#8216; This line converts x from a range object into an array, it speeds things up hugely!<br />
x = x.value<br />
&#8216; Then read whichever value you want from the array<br />
ReadCell = x(1,1)<br />
End Function</p>
<p>&#8220;As far as I know, I&#8217;ve never written a function that I&#8217;ve used in a cell AND called from a Sub procedure. It&#8217;s usually one or the other.&#8221;</p>
<p>I do that all the time.  Like this:</p>
<p>Function RtoP(Coords As Variant, Optional Origin As Variant, Optional Result As Long) As Variant<br />
    Dim &#8230;</p>
<p>    If TypeName(Coords) = &#8220;Range&#8221; Then<br />
        Coords = Coords.Value<br />
    End If<br />
    &#8230;.</p>
<p>So if the function is called from a worksheet, and Coords is a range, it gets converted into an array.  If it is called from a sub it will usually be an array already, but if it isn&#8217;t it gets converted.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dick Kusleika</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-28012</link>
		<dc:creator>Dick Kusleika</dc:creator>
		<pubDate>Thu, 11 Oct 2007 20:15:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-28012</guid>
		<description>&lt;p&gt;Jeffrey:  Since x is already a range, you&#039;d use&lt;/p&gt;
&lt;p&gt;ReadCell = x.Value&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Jeffrey:  Since x is already a range, you&#8217;d use</p>
<p>ReadCell = x.Value</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeffrey pattavina</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-28010</link>
		<dc:creator>Jeffrey pattavina</dc:creator>
		<pubDate>Thu, 11 Oct 2007 17:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-28010</guid>
		<description>&lt;p&gt;I am having trouble entering a range arguement for my functions. &lt;/p&gt;
&lt;p&gt;The following Function should read the cell designated by the range x hwever it does not work. Any thoughts?&lt;/p&gt;
&lt;p&gt;ReadCell(x As Range)&lt;br&gt;
ReadCell = Cells(x).Value&lt;br&gt;
End Function&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I am having trouble entering a range arguement for my functions. </p>
<p>The following Function should read the cell designated by the range x hwever it does not work. Any thoughts?</p>
<p>ReadCell(x As Range)<br />
ReadCell = Cells(x).Value<br />
End Function</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ahn</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-27863</link>
		<dc:creator>ahn</dc:creator>
		<pubDate>Thu, 04 Oct 2007 01:01:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-27863</guid>
		<description>&lt;p&gt;thank&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>thank</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Vidas</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-25430</link>
		<dc:creator>Matt Vidas</dc:creator>
		<pubDate>Mon, 09 Jul 2007 19:08:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-25430</guid>
		<description>&lt;p&gt;Harold,&lt;/p&gt;
&lt;p&gt;A range object has a Calculate method, so you should be able to just do something like:&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; HaroldCalculateSelectedCells()&lt;br&gt;
&#160;&lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; TypeName(Selection) = &lt;span class=&quot;st0&quot;&gt;&quot;Range&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; Selection.Calculate&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;
&lt;p&gt;Matt&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Harold,</p>
<p>A range object has a Calculate method, so you should be able to just do something like:</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> HaroldCalculateSelectedCells()<br />
&nbsp;<span class="kw1">If</span> TypeName(Selection) = <span class="st0">&#8220;Range&#8221;</span> <span class="kw1">Then</span> Selection.Calculate<br />
<span class="kw1">End</span> <span class="kw1">Sub</span></div>
</div>
<p>Matt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harold Odom</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-25427</link>
		<dc:creator>Harold Odom</dc:creator>
		<pubDate>Mon, 09 Jul 2007 15:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-25427</guid>
		<description>&lt;p&gt;I created the following Macro that causes the selected and some cases the whole sheet to recalculate upon pressing Ctrl+Shift+C&lt;/p&gt;
&lt;p&gt;There must be a control in Excel to accomplish the same.&lt;/p&gt;
&lt;p&gt;Sub Macro3()&lt;br&gt;
&#039;&lt;br&gt;
&#039; Macro3 Macro&lt;br&gt;
&#039; Macro recorded 7/9/2007 by B2HPOHLO&lt;br&gt;
&#039;&lt;br&gt;
&#039; Keyboard Shortcut: Ctrl+Shift+C&lt;br&gt;
&#039;&lt;br&gt;
    ActiveCell.Select&lt;br&gt;
    ActiveCell.FormulaR1C1 = ActiveCell.FormulaR1C1&lt;br&gt;
End Sub&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I created the following Macro that causes the selected and some cases the whole sheet to recalculate upon pressing Ctrl+Shift+C</p>
<p>There must be a control in Excel to accomplish the same.</p>
<p>Sub Macro3()<br />
&#8216;<br />
&#8216; Macro3 Macro<br />
&#8216; Macro recorded 7/9/2007 by B2HPOHLO<br />
&#8216;<br />
&#8216; Keyboard Shortcut: Ctrl+Shift+C<br />
&#8216;<br />
    ActiveCell.Select<br />
    ActiveCell.FormulaR1C1 = ActiveCell.FormulaR1C1<br />
End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jane</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-1392</link>
		<dc:creator>Jane</dc:creator>
		<pubDate>Mon, 20 Sep 2004 19:52:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-1392</guid>
		<description>&lt;p&gt;thank you, but what if i want Excel to look at the contents of one cell, and use another cell&#039;s value to calculate.  That is, total values based on their definition?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>thank you, but what if i want Excel to look at the contents of one cell, and use another cell&#8217;s value to calculate.  That is, total values based on their definition?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Errol Francis</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-1391</link>
		<dc:creator>Errol Francis</dc:creator>
		<pubDate>Tue, 25 May 2004 13:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-1391</guid>
		<description>&lt;p&gt;Excellent site!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Excellent site!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dick</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-1390</link>
		<dc:creator>Dick</dc:creator>
		<pubDate>Fri, 23 Apr 2004 20:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-1390</guid>
		<description>&lt;p&gt;Russ:  That function doesn&#039;t use any files, so I doubt that it&#039;s the culprit.  Did you make any other changes?  Generally, for startup errors I do the following:&lt;/p&gt;
&lt;p&gt;1.  Run the Workbook_Open of Personal.xls and any other workbooks that open automatically.  Do this with the workbooks already open and see which one gives you an error, if any.&lt;/p&gt;
&lt;p&gt;2.  Write down all the add-ins that are installed.  Uncheck them one-by-one and restart excel until you don&#039;t get an error.  The last one you unchecked has the error.&lt;/p&gt;
&lt;p&gt;3.  Reregister excel by going to Start Run and typing &quot;excel.exe /regserver&quot; (no qutoes)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Russ:  That function doesn&#8217;t use any files, so I doubt that it&#8217;s the culprit.  Did you make any other changes?  Generally, for startup errors I do the following:</p>
<p>1.  Run the Workbook_Open of Personal.xls and any other workbooks that open automatically.  Do this with the workbooks already open and see which one gives you an error, if any.</p>
<p>2.  Write down all the add-ins that are installed.  Uncheck them one-by-one and restart excel until you don&#8217;t get an error.  The last one you unchecked has the error.</p>
<p>3.  Reregister excel by going to Start Run and typing &#8220;excel.exe /regserver&#8221; (no qutoes)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juan Pablo</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/04/22/beginning-vba-your-first-function/#comment-1389</link>
		<dc:creator>Juan Pablo</dc:creator>
		<pubDate>Fri, 23 Apr 2004 19:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=488#comment-1389</guid>
		<description>&lt;p&gt;Raph,&lt;/p&gt;
&lt;p&gt;No, that&#039;s the way Excel is designed.  Changing the format of a cell doesn&#039;t trigger a recalculation, which seems logical.  So you have to either put&lt;/p&gt;
&lt;p&gt;Application.Volatile True&lt;/p&gt;
&lt;p&gt;at the top of the function and it will recalculate itself each time any cell changes, or force a recalculation using&lt;/p&gt;
&lt;p&gt;Control Shift F9&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Raph,</p>
<p>No, that&#8217;s the way Excel is designed.  Changing the format of a cell doesn&#8217;t trigger a recalculation, which seems logical.  So you have to either put</p>
<p>Application.Volatile True</p>
<p>at the top of the function and it will recalculate itself each time any cell changes, or force a recalculation using</p>
<p>Control Shift F9</p>
]]></content:encoded>
	</item>
</channel>
</rss>

