Filling in an array with data from a range that fall below the average

seigna

New Member
Joined
Apr 26, 2013
Messages
9
I am trying to select those values from a one-dimensional range of data that fall below the average. Also, I am trying to count how many of them there are, and finally, to calculate the variance.
This code doesn't seem to be working and I think the problem comes when I populate the array :/


Code:
 Function MoyBelow(data As Range) As Variant     
    Dim i As Integer     
    Dim N As Long     
    Redim BelowAvg() As Variant     
    Dim Varian As Double     
    Dim Somcar() As Variant          

    N=WorksheetFunction.Average(data)     
    RendMoy=WorksheetFunction.Average(data)          

        For i=1 To N         
            If data.Cells(i).Value < RendMoy Then             
                BelowAvg(i).Value = data(i).Value         
        End If         
        NB = BelowAvg.Count                  
        
             For j=1 To NB             
                 SumSq= SumSq + (BelowAvg(i) - RendMoy)^2        
             Next i                  
   
             Varian = Somcar/NB     

    End Function
 
Last edited:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,214,982
Messages
6,122,575
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top