Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to tell the AVERAGE function to avoid non numerical values

I’ve got a worksheet that looks something like this

enter image description here

and what I want to do is average the values on each column using vba.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If I use the =AVERAGE() formula, that works fine and it ignores the N/A in the columns. But I need to do this with vba.

If I try to do something like

Sub test()

Worksheets("Sheet1").Range("C17").Value = WorksheetFunction.Average("C2:C14")

End Sub

Then I get a message saying "Unable to get the Average property of the WorksheetFunction class"

Is there any way I can tell my code to avoid the "N/A" when it calculates the averages so I don’t get this issue?

>Solution :

Since Average doesn’t take a string input, use

WorksheetFunction.Average(Worksheets("Sheet1").Range("C2:C14"))

rather than just WorksheetFunction.Average("C2:C14")

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading