Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Averageing a collection

hello

i need the average of a collection

val is the name of a collection, here is the line of code:

a = application.worksheetfunction.average(val)


I tried this and it get an run time error 1004 unable to get th
average property of the worksheet function.

Is there something wrong with my VBA or is it that I can't use
collection like this?

Is there a way to average a collection? I have tried to averag
numbers in the argument list and it works just fine

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Averageing a collection

if your talking about a collection as used by VBA, like Workbooks collection, then a collection is an Object not a numeric value, and cannot be used in that function

----- ksnapp wrote: ----

hell

i need the average of a collectio

val is the name of a collection, here is the line of code

a = application.worksheetfunction.average(val


I tried this and it get an run time error 1004 unable to get th
average property of the worksheet function

Is there something wrong with my VBA or is it that I can't use
collection like this

Is there a way to average a collection? I have tried to averag
numbers in the argument list and it works just fine


--
Message posted from http://www.ExcelForum.com


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Averageing a collection

Hi ksnapp,

The worksheet function axpects a RANGE in stead of a COLLECTION.

A range can be several non connected cells, or a names range.


good luck,

Wouter



ksnapp wrote in message ...
hello

i need the average of a collection

val is the name of a collection, here is the line of code:

a = application.worksheetfunction.average(val)


I tried this and it get an run time error 1004 unable to get the
average property of the worksheet function.

Is there something wrong with my VBA or is it that I can't use a
collection like this?

Is there a way to average a collection? I have tried to average
numbers in the argument list and it works just fine.


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Averageing a collection

Hello ksnapp

Here's some example code:

Sub AverageOfCollection()
'Leo Heuser, 16 Apr. 2004
Dim CollSum As Double
Dim Counter As Long
Dim TestArray As Variant
Dim TestColl As New Collection

TestArray = Array(1, 3, 4, 6, 7)

On Error Resume Next

For Counter = LBound(TestArray) To UBound(TestArray)
TestColl.Add Item:=TestArray(Counter)
Next Counter

For Counter = 1 To TestColl.Count
CollSum = CollSum + TestColl(Counter)
Next Counter

MsgBox "Average is: " & CollSum / TestColl.Count

End Sub

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"ksnapp " skrev i en meddelelse
...
hello

i need the average of a collection

val is the name of a collection, here is the line of code:

a = application.worksheetfunction.average(val)


I tried this and it get an run time error 1004 unable to get the
average property of the worksheet function.

Is there something wrong with my VBA or is it that I can't use a
collection like this?

Is there a way to average a collection? I have tried to average
numbers in the argument list and it works just fine.


---
Message posted from http://www.ExcelForum.com/



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
Averageing monthly data by type Mudbug Excel Discussion (Misc queries) 2 October 22nd 08 01:23 PM
AVERAGEing non contiguous rows Mike McLellan Excel Discussion (Misc queries) 2 April 14th 08 09:21 PM
Averageing Costs Harlan Excel Discussion (Misc queries) 2 March 5th 07 04:09 AM
Reset New Collection Tony Di Stasi[_2_] Excel Programming 2 February 19th 04 03:21 PM
2 Collection questions Stuart[_5_] Excel Programming 5 January 30th 04 04:50 PM


All times are GMT +1. The time now is 06:43 PM.

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"