Hello everyone,
Iam trying to remove outliers in a graph.
Were in collumn A is the time (1,2,3,4,5 etc)
Collumn B are the values (15,10,1,4,5,6 etc)
Iam trying to remove the outliers from the grahp but iam getting the error 1004 Unable to get StDev property of Worksheet Class.
this is my code
Iam trying to remove outliers in a graph.
Were in collumn A is the time (1,2,3,4,5 etc)
Collumn B are the values (15,10,1,4,5,6 etc)
Iam trying to remove the outliers from the grahp but iam getting the error 1004 Unable to get StDev property of Worksheet Class.
this is my code
VBA Code:
Sub RemoveOutliers()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Blad1") ' Replace "Sheet1" with your sheet name
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
Dim mean As Double, sd As Double
Dim i As Long, j As Long
For i = 2 To lastRow ' Assumes data starts in row 2
mean = WorksheetFunction.Average(ws.Range("B" & i))
sd = Application.WorksheetFunction.StDev_S(ws.Range("B" & i))
For j = 1 To 1 ' Only one column
If Abs(ws.Cells(i, j + 1).Value - mean) > (2 * sd) Then
ws.Cells(i, j + 1).ClearContents
End If
Next j
Next i
End Sub