#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Average

I have written some code to find out average of some
numbers. Although if i used Excel's existing formula,
average, to work it out, the result would be different
(about less than 1% for an average of 720 numbers) from
that derived using my own code.
I wonder if the difference is due to rounding errors. Is
it possible to take a look at the code behind Excel's
existing formulas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Average

No, it isn't possible. But I suspect the error is on your end <bg.


On Wed, 29 Sep 2004 18:35:53 -0700, "Darren" wrote:

I have written some code to find out average of some
numbers. Although if i used Excel's existing formula,
average, to work it out, the result would be different
(about less than 1% for an average of 720 numbers) from
that derived using my own code.
I wonder if the difference is due to rounding errors. Is
it possible to take a look at the code behind Excel's
existing formulas?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Average

Thanks for the reply.

Do you know then, the syntax to use if i want to use
Excel's average formula for col A, rows i to j? rows i and
j?
If i and j are both variables

Thanks
Darren

-----Original Message-----
No, it isn't possible. But I suspect the error is on your

end <bg.


On Wed, 29 Sep 2004 18:35:53 -0700, "Darren"

wrote:

I have written some code to find out average of some
numbers. Although if i used Excel's existing formula,
average, to work it out, the result would be different
(about less than 1% for an average of 720 numbers) from
that derived using my own code.
I wonder if the difference is due to rounding errors. Is
it possible to take a look at the code behind Excel's
existing formulas?


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Average

You can use most worksheet functions within your VBA code. Exceptions are
cases where VBA has its own function that does the same thing, but that
doesn't apply to AVERAGE. The syntax is

Set Rng = Cells(i, 1).Resize(j - i + 1, 1)
Avg = Application.Average(Rng)

or, putting it all into one statement:

Avg = Application.Average(Cells(i, 1).Resize(j - i + 1, 1))


On Wed, 29 Sep 2004 21:14:20 -0700, "Darren" wrote:

Thanks for the reply.

Do you know then, the syntax to use if i want to use
Excel's average formula for col A, rows i to j? rows i and
j?
If i and j are both variables

Thanks
Darren

-----Original Message-----
No, it isn't possible. But I suspect the error is on your

end <bg.


On Wed, 29 Sep 2004 18:35:53 -0700, "Darren"

wrote:

I have written some code to find out average of some
numbers. Although if i used Excel's existing formula,
average, to work it out, the result would be different
(about less than 1% for an average of 720 numbers) from
that derived using my own code.
I wonder if the difference is due to rounding errors. Is
it possible to take a look at the code behind Excel's
existing formulas?


.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Average

PS: You really ought to study your code to see why you are getting a different
answer. You always learn something from "debugging".

Are you sure this isn't just a rounding issue? If the cells on the worksheet
are the result of formulas, but displayed with, say, 2 decimal places, when
you use the AVERAGE formula, the complete number is used, not the rounded
version that you see. If you are working with the rounded numbers in your
code, you'll get a different result.

On Wed, 29 Sep 2004 21:14:20 -0700, "Darren" wrote:

Thanks for the reply.

Do you know then, the syntax to use if i want to use
Excel's average formula for col A, rows i to j? rows i and
j?
If i and j are both variables

Thanks
Darren

-----Original Message-----
No, it isn't possible. But I suspect the error is on your

end <bg.


On Wed, 29 Sep 2004 18:35:53 -0700, "Darren"

wrote:

I have written some code to find out average of some
numbers. Although if i used Excel's existing formula,
average, to work it out, the result would be different
(about less than 1% for an average of 720 numbers) from
that derived using my own code.
I wonder if the difference is due to rounding errors. Is
it possible to take a look at the code behind Excel's
existing formulas?


.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A formula to AVERAGE IF but only average a set number of values [email protected] Excel Worksheet Functions 2 January 31st 08 08:28 PM
Find monthly average but have average automatically configured kimbafred Excel Discussion (Misc queries) 2 August 8th 07 12:28 AM
Error Handling #N/A with AVERAGE Function - Average of values in Row Sam via OfficeKB.com Excel Worksheet Functions 13 July 31st 05 03:59 PM
Weighed Average of a weiged average when there are blanks krl - ExcelForums.com Excel Discussion (Misc queries) 1 July 6th 05 07:37 PM
how does one convert text to a formula "average(A:A)" to =average( phshirk Excel Worksheet Functions 4 April 14th 05 01:20 AM


All times are GMT +1. The time now is 12:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"