I have a macro that is building an array. The array has 400 columns and 1000 rows. I need outliers identified from each data column, not the total data cloud. I have to post the data in the worksheet first and then do the calculation. I'm using the code below. The code calculates the values in the worksheet. But it takes too long to calculate. I need to speed up the code, but I can not find the correct syntax. I'd like to first calculate in the array and then throw them in the worksheet. Is it possible? Thx for support.
Sub outliers()
Dim mAvg As Double, mStdD As Double
Dim rData As Range, rCell As Range, Rng As Range
Set rData = Range("B2:OK1001")
For Each rCell In rData.Columns
mAvg = WorksheetFunction.Average(rCell )
mStdD = WorksheetFunction.StDev(rCell )
For i = 1 To rCell .Cells.Count
Set Rng = rCell .Cells(i, 1)
If Rng <> "-" Then
If Rng <> "" Then
If Rng > mAvg + 1 * mStdD Or Rng < mAvg - 1 * mStdD Then
Rng.Value = "Outlier"
End If: End If: End If
Next i: Next
End Sub
Sub outliers()
Dim mAvg As Double, mStdD As Double
Dim rData As Range, rCell As Range, Rng As Range
Set rData = Range("B2:OK1001")
For Each rCell In rData.Columns
mAvg = WorksheetFunction.Average(rCell )
mStdD = WorksheetFunction.StDev(rCell )
For i = 1 To rCell .Cells.Count
Set Rng = rCell .Cells(i, 1)
If Rng <> "-" Then
If Rng <> "" Then
If Rng > mAvg + 1 * mStdD Or Rng < mAvg - 1 * mStdD Then
Rng.Value = "Outlier"
End If: End If: End If
Next i: Next
End Sub