mjdubya
New Member
- Joined
- May 10, 2011
- Messages
- 2
Hey Folks,
I am experiencing a "Unable to get the Average property of the WorksheetFunction class" runtime error. I wasn't able to figure out the problem from responses to similar posts.
I am attempting to get the average and maximum values from each column of data into respective AvgValArray and MaxValArray and then print the max and average values into column A & B. Note that the MaxValArray performs fine. It's only the AvgValArray (line in red) that results in runtime error.
The code:
Sub InsertMaxAvgVals()
Dim ColInserts As Integer, Count As Integer, LastCol As Integer, LastRow As Integer, ArrSize As Integer
Dim MaxValArray() As Double, AvgValArray() As Double
LastCol = Cells.SpecialCells(xlCellTypeLastCell).Column
LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
ReDim MaxValArray(1 To LastCol)
ReDim AvgValArray(1 To LastCol)
ColInserts = 2
For i = 1 To ColInserts
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Next
'Takes the max and average of each column and puts in respective arrays
For Count = 4 To LastCol
MaxValArray(Count - 3) = WorksheetFunction.Max(Range(Cells(3, Count), Cells(LastRow, Count)))
AvgValArray(Count - 3) = WorksheetFunction.Average(Range(Cells(3, Count), Cells(LastRow, Count)))
Next
'Writes max and average values in Columns A & B
For i = 1 To LastCol - 7
Cells(i + 2, 1) = MaxValArray(i)
Cells(i + 2, 2) = AvgValArray(i)
Next
End Sub
The Data:
eh.. can't attach?????
Verbal description:
Data is positive double precision
Organized in Columns starting at Column B with no empty columns
Varying number of values per column
Several Empty cells within column data
Your input is much appreciated!!
I am experiencing a "Unable to get the Average property of the WorksheetFunction class" runtime error. I wasn't able to figure out the problem from responses to similar posts.
I am attempting to get the average and maximum values from each column of data into respective AvgValArray and MaxValArray and then print the max and average values into column A & B. Note that the MaxValArray performs fine. It's only the AvgValArray (line in red) that results in runtime error.
The code:
Sub InsertMaxAvgVals()
Dim ColInserts As Integer, Count As Integer, LastCol As Integer, LastRow As Integer, ArrSize As Integer
Dim MaxValArray() As Double, AvgValArray() As Double
LastCol = Cells.SpecialCells(xlCellTypeLastCell).Column
LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
ReDim MaxValArray(1 To LastCol)
ReDim AvgValArray(1 To LastCol)
ColInserts = 2
For i = 1 To ColInserts
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Next
'Takes the max and average of each column and puts in respective arrays
For Count = 4 To LastCol
MaxValArray(Count - 3) = WorksheetFunction.Max(Range(Cells(3, Count), Cells(LastRow, Count)))
AvgValArray(Count - 3) = WorksheetFunction.Average(Range(Cells(3, Count), Cells(LastRow, Count)))
Next
'Writes max and average values in Columns A & B
For i = 1 To LastCol - 7
Cells(i + 2, 1) = MaxValArray(i)
Cells(i + 2, 2) = AvgValArray(i)
Next
End Sub
The Data:
eh.. can't attach?????
Verbal description:
Data is positive double precision
Organized in Columns starting at Column B with no empty columns
Varying number of values per column
Several Empty cells within column data
Your input is much appreciated!!