Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Error msg: Unable to access Worksheet function

Posted on 2002-03-26
9
320 Views
Last Modified: 2012-06-21
I am writing a function in VBA which needs to find the average of a range of cells.
the range varies, so is passed to my function by another function (which I have tested and works fine).

My function looks like this:

Function AvSqFtbyQ(quart As Integer) As Integer
'calculates the average square footage per quartile
Dim hold As Integer
Dim Rng As String

Rng = GetRangeQ(quart)
hold = Application.WorksheetFunction.Average(Rng)
AvSqFtbyQ = hold

End Function


When I test it in the Immediate Window I get error number 1004: "Unable to get the Average property of the Worksheet Function Class."

am I missing a reference library or do I need to install something?

any ideas as to what is going on here?

thanks, I know I've been asking a lot of questions lately!

Sasha

0
Comment
Question by:SBFurr
  • 6
  • 3
9 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 6897404
Hi Sasha, what does the getrange exactly return? i see a string this modified one works

Function AvSqFtbyQ(quart As Integer) As Integer
'calculates the average square footage per quartile
Dim hold As Integer
Dim Rng As Range

Set Rng = GetRangeQ(quart)
hold = Application.WorksheetFunction.Average(Rng)
AvSqFtbyQ = hold

End Function

presuming your return a range from the getrange function

HTH:O)Bruintje
0
 

Author Comment

by:SBFurr
ID: 6897447
actually GetRangeQ returns a string.

I tried just typing in the value in the Immediate window,
debug.pring application.WorksheetFunction.average(C4:C14)
and got the same error #1004.

thanks
Sasha
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6897471
the sring must be formatted like "C4:C14" and tehn this will do

hold = Application.WorksheetFunction.Average(Range(Rng))

HTH:O)Bruintje
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:SBFurr
ID: 6897508
one more detail, how do I get the "s around it?
if I tell it
hold = Application.WorksheetFunction.Average(Range(" & Rng & "))
It thinks I'm telling it "& Rng &"

thanks,
Sasha
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6897521
didn't it work? with the returned string?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6897540
or try  Rng = "(" & quart & ")"
0
 
LVL 44

Accepted Solution

by:
bruintje earned 50 total points
ID: 6897591
allright a bit of rereading

getrange(X) returns a string like C10:C14

then

hold = Application.WorksheetFunction.Average(Range(Rng))

has to work as is without any formatting or does it not?

i presume this is a folloow up on your access question?

:O)Bruintje
0
 

Author Comment

by:SBFurr
ID: 6897650
why, yes it is a follow-up to my access question :)
I'm almost done with this project.

hold = Application.WorksheetFunction.Average(Range(Rng))
works, I had mistyped it.

thanks for all your help!

you might see questions on creating graphs in VBA tomorrow...

Sasha
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6897758
;) looking forward to it
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some time ago I was asked to create a VBA function that would calculate a check digit for an input number, using the following procedure: First, sum up all the individual digits in the number If that sum value has more than one digit, then sum up …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question