(Another) Unable to get the Average property of the WorksheetFunction class example

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!!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I just found a very unsatisfying solution:

Turn off computer, walk dog, drink a beer, turn on computer, re-run macro without changing the code.

Not sure why I was receiving error prior......
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top