warlordusa
New Member
- Joined
- Jan 13, 2023
- Messages
- 1
Hello all,
Below is apart of my code where I take a range of data, and try to find the avg, max, min, and now stdev. I am getting values for my avg max min, but nothing for my std, specifically this line of code:
Std = Application.WorksheetFunction.StDev_S(MyRange)
Any help would be appreciated.
Thanks
Code here:
Dim CurrentColumn As Integer
CurrentColumn = 5 '=5 because results start on column E
Dim LastColumn As Integer
'Find the last used Column
LastColumn = Sheet1.Cells(7, Columns.Count).End(xlToLeft).Column
'Loop to get all of the results and formats in each column
Do While CurrentColumn <= LastColumn
Dim MyRange As Range
Dim Avg As Double
Dim Min As Double
Dim Max As Double
Dim Std As Double
Dim AvgPlusStd As Double
Dim AvgMinStd As Double
Set MyRange = Range(Cells(7, CurrentColumn), Cells(LastDataRow, CurrentColumn))
'Put Average, Max, and Min In Table
'And now Stdev and +/- 3 Dev
On Error Resume Next ' This line ignores an error and goes to the next line of code. This is usefull when trying to take the
Avg = Application.WorksheetFunction.Average(MyRange)
Min = Application.WorksheetFunction.Min(MyRange)
Max = Application.WorksheetFunction.Max(MyRange)
Std = Application.WorksheetFunction.StDev_S(MyRange)
AvgPlusStd = Avg + (3 * Std)
AvgMinStd = Avg - (3 * Std)
If AvgMinStd < 0 Then
AvgMinStd = 0
End If
Sheet1.Cells(AvgRow, CurrentColumn).Value = Avg
Sheet1.Cells(MinRow, CurrentColumn).Value = Min
Sheet1.Cells(MaxRow, CurrentColumn).Value = Max
Below is apart of my code where I take a range of data, and try to find the avg, max, min, and now stdev. I am getting values for my avg max min, but nothing for my std, specifically this line of code:
Std = Application.WorksheetFunction.StDev_S(MyRange)
Any help would be appreciated.
Thanks
Code here:
Dim CurrentColumn As Integer
CurrentColumn = 5 '=5 because results start on column E
Dim LastColumn As Integer
'Find the last used Column
LastColumn = Sheet1.Cells(7, Columns.Count).End(xlToLeft).Column
'Loop to get all of the results and formats in each column
Do While CurrentColumn <= LastColumn
Dim MyRange As Range
Dim Avg As Double
Dim Min As Double
Dim Max As Double
Dim Std As Double
Dim AvgPlusStd As Double
Dim AvgMinStd As Double
Set MyRange = Range(Cells(7, CurrentColumn), Cells(LastDataRow, CurrentColumn))
'Put Average, Max, and Min In Table
'And now Stdev and +/- 3 Dev
On Error Resume Next ' This line ignores an error and goes to the next line of code. This is usefull when trying to take the
Avg = Application.WorksheetFunction.Average(MyRange)
Min = Application.WorksheetFunction.Min(MyRange)
Max = Application.WorksheetFunction.Max(MyRange)
Std = Application.WorksheetFunction.StDev_S(MyRange)
AvgPlusStd = Avg + (3 * Std)
AvgMinStd = Avg - (3 * Std)
If AvgMinStd < 0 Then
AvgMinStd = 0
End If
Sheet1.Cells(AvgRow, CurrentColumn).Value = Avg
Sheet1.Cells(MinRow, CurrentColumn).Value = Min
Sheet1.Cells(MaxRow, CurrentColumn).Value = Max