For reference, here is the whole code.
Sub CalculateOutliers()
Dim n As Long
Dim mean As Double
Dim SD As Double
Dim k As Long
Dim DataSet As Variant
Dim LowConf As Double
Dim HighConf As Double
'--------------------------------------------------------
DataSet = Selection.Value
'Copies highlighted data into DataSet variable
'Cell A1 is (1,1) Because it starts at 0 which is out of range
'--------------------------------------------------------
'--------------------------------------------------------
n = Selection.CountLarge
'Counts number of entries
'--------------------------------------------------------
'--------------------------------------------------------
'DEFINES 95(LowConf) AND 99(HighConf) PERCENT CONFIDENCES BASED ON
'SAMPLE SIZE
If n <= 5 Then
LowConf = 1.72
HighConf = 1.76
End If
If n = 6 Then
LowConf = 1.89
HighConf = 1.97
End If
If n = 7 Then
LowConf = 2.02
HighConf = 2.14
End If
If n = 8 Then
LowConf = 2.13
HighConf = 2.28
End If
If n = 9 Then
LowConf = 2.21
HighConf = 2.39
End If
If n = 10 Then
LowConf = 2.29
HighConf = 2.48
End If
If n = 11 Then
LowConf = 2.36
HighConf = 2.56
End If
If n = 12 Then
LowConf = 2.41
HighConf = 2.64
End If
If n = 13 Then
LowConf = 2.46
HighConf = 2.7
End If
If n = 14 Then
LowConf = 2.51
HighConf = 2.75
End If
If n = 15 Then
LowConf = 2.55
HighConf = 2.81
End If
If n = 16 Then
LowConf = 2.59
HighConf = 2.85
End If
If n = 17 Then
LowConf = 2.62
HighConf = 2.9
End If
If n = 18 Then
LowConf = 2.65
HighConf = 2.93
End If
If n = 19 Then
LowConf = 2.68
HighConf = 2.97
End If
If n = 20 Then
LowConf = 2.71
HighConf = 3
End If
If n = 21 Then
LowConf = 2.73
HighConf = 3.03
End If
If n = 22 Then
LowConf = 2.76
HighConf = 3.06
End If
If n = 23 Then
LowConf = 2.78
HighConf = 3.08
End If
If n = 24 Then
LowConf = 2.8
HighConf = 3.11
End If
If n = 25 Then
LowConf = 2.82
HighConf = 3.14
End If
If n = 26 Then
LowConf = 2.84
HighConf = 3.16
End If
If n = 27 Then
LowConf = 2.86
HighConf = 3.18
End If
If n = 28 Then
LowConf = 2.88
HighConf = 3.2
End If
If n = 29 Then
LowConf = 2.89
HighConf = 3.22
End If
If n = 30 Then
LowConf = 2.91
HighConf = 3.24
End If
If n <= 35 And n > 30 Then
LowConf = 2.98
HighConf = 3.32
End If
If n <= 40 And n > 35 Then
LowConf = 3.04
HighConf = 3.38
End If
If n <= 45 And n > 40 Then
LowConf = 3.09
HighConf = 3.44
End If
If n <= 50 And n > 45 Then
LowConf = 3.13
HighConf = 3.48
End If
If n <= 60 And n > 50 Then
LowConf = 3.2
HighConf = 3.56
End If
If n <= 70 And n > 60 Then
LowConf = 3.26
HighConf = 3.62
End If
If n <= 80 And n > 70 Then
LowConf = 3.31
HighConf = 3.67
End If
If n <= 90 And n > 80 Then
LowConf = 3.35
HighConf = 3.72
End If
If n <= 100 And n > 90 Then
LowConf = 3.38
HighConf = 3.75
End If
If n <= 150 And n > 100 Then
LowConf = 3.52
HighConf = 3.89
End If
If n <= 200 And n > 150 Then
LowConf = 3.61
HighConf = 3.98
End If
If n <= 300 And n > 200 Then
LowConf = 3.72
HighConf = 4.09
End If
If n <= 400 And n > 300 Then
LowConf = 3.8
HighConf = 4.17
End If
If n <= 500 And n > 400 Then
LowConf = 3.86
HighConf = 4.32
End If
If n > 500 Then
MsgBox "Sample size cannot exceed 500."
End If
'--------------------------------------------------------
'--------------------------------------------------------
If n < 50 Then
k = Int(n / 10)
Else
k = 5
End If
'determines k = number of possible outliers
'--------------------------------------------------------
Dim i As Long
For i = 1 To k
'--------------------------------------------------------
mean = Application.WorksheetFunction.Average(DataSet)
'Calculates mean of Data Set
'--------------------------------------------------------
'--------------------------------------------------------
SD = Application.WorksheetFunction.StDev(DataSet)
'Calculates Standard Deviation of Data Set
'--------------------------------------------------------
'--------------------------------------------------------
Dim Suspect As Double
If (Abs(Application.WorksheetFunction.Max(DataSet) - mean)) > (Abs(Application.WorksheetFunction.Min(DataSet) - mean)) Then
Suspect = Application.WorksheetFunction.Max(DataSet)
End If
If (Abs(Application.WorksheetFunction.Max(DataSet) - mean)) < (Abs(Application.WorksheetFunction.Min(DataSet) - mean)) Then
Suspect = Application.WorksheetFunction.Min(DataSet)
End If
'Defines what the most outlying value is
'--------------------------------------------------------
'--------------------------------------------------------
Dim Retest As Boolean
If (Abs(Suspect - mean) / SD) > LowConf Then
MsgBox "95% outlier: " & Suspect
Retest = True
End If
If (Abs(Suspect - mean) / SD) > HighConf Then
MsgBox "99% outlier: " & Suspect
Retest = True
End If
If Retest = True Then
'--------------------------------------------------------
Next i
End Sub
Talking about this chunk of code, I need to delete Suspect from DataSet then shrink DataSet by 1 but I am not sure how to go about this. Is there a function that will delete the Max or Min value and is there a way to resize DataSet given that it is a variant?
Dim Retest As Boolean
If (Abs(Suspect - mean) / SD) > LowConf Then
MsgBox "95% outlier: " & Suspect
Retest = True
End If
If (Abs(Suspect - mean) / SD) > HighConf Then
MsgBox "99% outlier: " & Suspect
Retest = True
End If
If Retest = True Then