View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
ExcelMonkey ExcelMonkey is offline
external usenet poster
 
Posts: 553
Default Average a range within an array

Seems to work. Is it not possible to take the average of the column items
without looping? From what I can see you have transferred all the data from
the first column in the original array, to a new 1-D array and used the
function on that new array.

EM

"Norman Jones" wrote:

Hi Excel Monkey,

Perhaps nearer to your intention try:

'=============
Public Sub Tester2()
Dim PeriodicArray As Variant
Dim PeriodicAvg As Double
Dim arr As Variant
Dim i As Long

'Load array, e.g.:
PeriodicArray = Range("A1").Resize(10, 30).Value

arr = PeriodicArray

For i = UBound(arr, 2) To 1 Step -1
ReDim Preserve arr(1 To 10, 1 To i)
Next i

PeriodicAvg = Application.Average(arr)

MsgBox PeriodicAvg

End Sub
'<<=============


---
Regards,
Norman


"Norman Jones" wrote in message
...
Hi Excel Monkey,

Perhaps try something like:

'=============
Public Sub Tester()
Dim rng As Range
Dim PeriodicAvg As Double

Set rng = Range("PeriodicArray")

PeriodicAvg = Application.Average(rng.Columns(1))

MsgBox PeriodicAvg

End Sub
'<<=============


---
Regards,
Norman