pass array value in average function...

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

pass array value in average function...

Post by sal21 »

I fill the array wit:

for y=0 to ....
....
ReDim Preserve strDBRows3(CONT2)
strDBRows3(CONT2) = strDBRows(3, Y)
CONT2 = CONT2 + 1
....
next y

now how to pass the filled strDBRows3, in this code:

Sub CALCOLO_MEDIE()

Dim RngAddr As String
Dim Rng As Range
Dim Avg As Double
Dim Min As Double
Dim Max As Double

Set Rng = strDBRows3(CONT2<error here
With Application.WorksheetFunction
Avg = .Average(Rng)
Min = .Min(Rng)
Max = .Max(Rng)
End With

End Sub


note:
strDBRows3 is pubblic dimensioned

User avatar
HansV
Administrator
Posts: 78394
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: pass array value in average function...

Post by HansV »

An array is not the same as a range. Fortunately, you don't need to use a range here. Average, Min and Max work fine with arrays. So you can use

Code: Select all

    With Application.WorksheetFunction
        Avg = .Average(strDBRows3)
        Min = .Min(strDBRows3)
        Max = .Max(strDBRows3)
   End With
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

Re: pass array value in average function...

Post by sal21 »

HansV wrote:An array is not the same as a range. Fortunately, you don't need to use a range here. Average, Min and Max work fine with arrays. So you can use

Code: Select all

    With Application.WorksheetFunction
        Avg = .Average(strDBRows3)
        Min = .Min(strDBRows3)
        Max = .Max(strDBRows3)
   End With
I l**** YOU :thankyou: :clapping: