<?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: Average Values, Exclude Extremes</title>
	<atom:link href="http://www.codeforexcelandoutlook.com/blog/2008/07/average-values-exclude-extremes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeforexcelandoutlook.com/blog/2008/07/average-values-exclude-extremes/</link>
	<description>Automation and VBA code for Microsoft® Excel and Outlook</description>
	<lastBuildDate>Thu, 29 Jul 2010 10:47:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/07/average-values-exclude-extremes/#comment-2497</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Mon, 29 Mar 2010 21:34:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=69#comment-2497</guid>
		<description>Your request reads like a homework question.

To return the average of all positive values in a range, one way is to first read the range into an array.

[cc lang=&#039;vb&#039;]Dim tempArray As Variant
Dim rng As Excel.Range
&#039; set rng = whatever your range is
tempArray = rng.Value[/cc]

Then loop through the range and check for values greater than zero.

[cc lang=&#039;vb&#039;]&#039; assumes single dimension array
Dim i As Long
Dim total As Long
Dim avg As Long
For i = LBound(tempArray) To UBound(tempArray)
  total = total + tempArray(i)
Next i[/cc]

Then get the average of all positive values:

[cc lang=&#039;vb&#039;]avg = total / UBound(tempArray)[/cc]</description>
		<content:encoded><![CDATA[<p>Your request reads like a homework question.</p>
<p>To return the average of all positive values in a range, one way is to first read the range into an array.</p>
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:630px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080;">Dim</span> tempArray <span style="color: #000080;">As</span> <span style="color: #000080;">Variant</span><br />
<span style="color: #000080;">Dim</span> rng <span style="color: #000080;">As</span> Excel.Range<br />
<span style="color: #008000;">' set rng = whatever your range is<br />
</span>tempArray = rng.Value</div></div>
<p>Then loop through the range and check for values greater than zero.</p>
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:630px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">' assumes single dimension array<br />
</span><span style="color: #000080;">Dim</span> i <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
<span style="color: #000080;">Dim</span> total <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
<span style="color: #000080;">Dim</span> avg <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
<span style="color: #000080;">For</span> i = <span style="color: #000080;">LBound</span>(tempArray) <span style="color: #000080;">To</span> <span style="color: #000080;">UBound</span>(tempArray)<br />
&nbsp; total = total + tempArray(i)<br />
<span style="color: #000080;">Next</span> i</div></div>
<p>Then get the average of all positive values:</p>
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:630px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">avg = total / <span style="color: #000080;">UBound</span>(tempArray)</div></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leo</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/07/average-values-exclude-extremes/#comment-2482</link>
		<dc:creator>Leo</dc:creator>
		<pubDate>Sat, 27 Mar 2010 05:53:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=69#comment-2482</guid>
		<description>I wrote the following subroutine .can anyone tell me what &#039;s wrong with this. I dont find anything going wrong bt its just nt working. This function is writen to clik any random cell to change the colour.

Sub ColourCell()

Rand = ActiveCell.Interior.colour

 ActiveCell.Interior.Color = WhatColour(RandInteger())
End Sub</description>
		<content:encoded><![CDATA[<p>I wrote the following subroutine .can anyone tell me what 's wrong with this. I dont find anything going wrong bt its just nt working. This function is writen to clik any random cell to change the colour.</p>
<p>Sub ColourCell()</p>
<p>Rand = ActiveCell.Interior.colour</p>
<p> ActiveCell.Interior.Color = WhatColour(RandInteger())<br />
End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leo</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/07/average-values-exclude-extremes/#comment-2481</link>
		<dc:creator>Leo</dc:creator>
		<pubDate>Sat, 27 Mar 2010 05:50:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=69#comment-2481</guid>
		<description>Hi,
How can I write a function PositiveAverage(R) which return the average of all the positive values in the range R ( any negative values will be excluded in calculating the average). Sue a double &#039;For .. next loop structure in the function. Work with the range object R(and not array variable) in writing this function.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
How can I write a function PositiveAverage(R) which return the average of all the positive values in the range R ( any negative values will be excluded in calculating the average). Sue a double 'For .. next loop structure in the function. Work with the range object R(and not array variable) in writing this function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/07/average-values-exclude-extremes/#comment-2353</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Tue, 09 Feb 2010 22:50:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=69#comment-2353</guid>
		<description>Thanks, I fixed it!</description>
		<content:encoded><![CDATA[<p>Thanks, I fixed it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will Smith</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/07/average-values-exclude-extremes/#comment-2352</link>
		<dc:creator>Will Smith</dc:creator>
		<pubDate>Tue, 09 Feb 2010 19:56:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=69#comment-2352</guid>
		<description>There is a mistake at the text lines:
I could also use
{=AVERAGE(IF(MyRange

Looks like the hypertext got in there to have the remainder of text &lt;strong&gt;

The array formula should be:
I could also use
{=AVERAGE(IF(MyRange&lt;MAX(MYRANGE),MYRANGE))}

Thought you would want to make the correction as your information is very helpful.
Will</description>
		<content:encoded><![CDATA[<p>There is a mistake at the text lines:<br />
I could also use<br />
{=AVERAGE(IF(MyRange</p>
<p>Looks like the hypertext got in there to have the remainder of text <strong></p>
<p>The array formula should be:<br />
I could also use<br />
{=AVERAGE(IF(MyRange&lt;MAX(MYRANGE),MYRANGE))}</p>
<p>Thought you would want to make the correction as your information is very helpful.<br />
Will</strong></p>
]]></content:encoded>
	</item>
</channel>
</rss>
