JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,676
- Office Version
- 365
- Platform
- Windows
I am working on a macro that will analyze data in a sheet table. To do that, it needs to calculate the mean and standard deviation of each of the data columns.
Here is the code I have now. It extracts each column from the overall table into arrNextCol and then calculates the mean and std dev from that.
Then it occurred to me that I really don't need that temporary array. I came up with this code. It extracts the column data twice.
Is there any significant difference in performance between the two methods?
Thanks
Here is the code I have now. It extracts each column from the overall table into arrNextCol and then calculates the mean and std dev from that.
VBA Code:
Dim arrNextCol() As Variant: ReDim arrNextCol(NumRows)
Dim Mean As Double
Dim StdDev As Double
For iCol = MinCols To NumCols 'Loop through the property columns
With Application.WorksheetFunction
arrNextCol = .Index(arrTableData, 0, iCol) 'Load data from the next column
Mean = .Average(arrNextCol)
StdDev = .StDev_S(arrNextCol)
End With
Next iCol
Then it occurred to me that I really don't need that temporary array. I came up with this code. It extracts the column data twice.
VBA Code:
Dim Mean As Double
Dim StdDev As Double
For iCol = MinCols To NumCols 'Loop through the property columns
With Application.WorksheetFunction
Mean = .Average(.Index(arrTableData, 0, iCol))
StdDev = .StDev_S(.Index(arrTableData, 0, iCol))
End With
Next iCol
Is there any significant difference in performance between the two methods?
Thanks