Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Averaging a range in VBA

Would someone be so kind as to get me started in the right direction.

Creating a UDF that initially needs to evaluate the average of a range,
however, Average is not a VBA function. I've tried the Evaluate function
with the worksheet function Average but my syntax must be wrong.

Is there an easy way or am I missing something. Here is the basis of
what I'm trying to do:

Function YearAvg(rng As Range)
YearAvg = Average(rng)
End Function


Thanks!
Bill

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Averaging a range in VBA

Hi Bill,

Try:

YearAvg = WorksheetFunction.Average(rng)

---
Regards,
Norman



"WilMar" wrote in message
...
Would someone be so kind as to get me started in the right direction.

Creating a UDF that initially needs to evaluate the average of a range,
however, Average is not a VBA function. I've tried the Evaluate function
with the worksheet function Average but my syntax must be wrong.

Is there an easy way or am I missing something. Here is the basis of
what I'm trying to do:

Function YearAvg(rng As Range)
YearAvg = Average(rng)
End Function


Thanks!
Bill

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Averaging a range in VBA

There is an AVERAGE function. In order to use it within VBA, you need to
prefix it with WorkSheetFunction.

Sub xx()
a = WorksheetFunction.Average(Range("A1:A5"))
MsgBox a
'or Range("B1").Value = WorksheetFunction.Average(Range("A1:A5"))
End Sub


"WilMar" wrote:

Would someone be so kind as to get me started in the right direction.

Creating a UDF that initially needs to evaluate the average of a range,
however, Average is not a VBA function. I've tried the Evaluate function
with the worksheet function Average but my syntax must be wrong.

Is there an easy way or am I missing something. Here is the basis of
what I'm trying to do:

Function YearAvg(rng As Range)
YearAvg = Average(rng)
End Function


Thanks!
Bill

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Averaging a range in VBA

Norman - thanks! Knew I was missing the obvious.

Thanks!
Bill

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
averaging a range suprsonic Excel Worksheet Functions 5 May 6th 10 04:15 AM
Averaging times that are not in a range Nancy D Excel Worksheet Functions 3 April 20th 10 05:19 PM
Averaging data if within a date range KellyF Excel Worksheet Functions 6 October 19th 07 03:45 PM
Changing the range of several averaging functions Hellion Excel Discussion (Misc queries) 1 September 17th 05 02:12 PM
Averaging a dynamic range...Help ??? wraithlead Excel Programming 1 July 9th 04 02:36 PM


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

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

About Us

"It's about Microsoft Excel"