Sub UseExcelFunctions()
Dim iColumnCount As Integer
Dim lRowCount As Long
Dim iCol As Integer
Dim dAverage As Double
Dim dStdDev As Double
Worksheets(2).Activate
' Count number of columns and rows in use...
iColumnCount = ActiveSheet.UsedRange.Columns.Count
lRowCount = ActiveSheet.UsedRange.Rows.Count
' Cycle through each non-empty column...
For iCol = 1 To iColumnCount
' Use the Average and StDev Excel functions to
' calculate values for each column...
dAverage = WorksheetFunction.Average(Columns(iCol))
dStdDev = WorksheetFunction.StDev(Columns(iCol))
' Place results below existing data...
Cells(lRowCount + 2, iCol).Value = dAverage
Cells(lRowCount + 3, iCol).Value = dStdDev
Next iCol
End Sub
No comments:
Post a Comment