+ Reply to Thread
Results 1 to 5 of 5

Array of Ranges to work out average value PROBLEM!

  1. #1
    Registered User
    Join Date
    07-19-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    2

    Angry Array of Ranges to work out average value PROBLEM!

    I'm trying to create an array of ranges to use with the average function, I would like each range to be processed and the average value found to be printed. I'm getting error 1004 "unable to get average property of worksheet function"

    Please Login or Register  to view this content.
    Last edited by AndresJanes; 07-19-2014 at 09:02 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: Array of Ranges to work out average value PROBLEM!

    Maybe:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Array of Ranges to work out average value PROBLEM!

    From my testing, if there are no numeric cells in any of those columns AVERAGE will return the #DIV/0 error if in a cell.
    In your use, with VBA, this results in the "Unable to get Average property" error message.
    Application.Worksheet.Average will result in a run time error.
    Application.Average will return an error value (but will then crash because RngAvrg1 is data type Long which is a type mismatch with the data type Error that it will return)

    If you declare RngAvrg1 as Variant and use Application.Average rather than Application.Worksheet.Average that should fix things.
    Please Login or Register  to view this content.
    or you could replace the whole thing with
    Please Login or Register  to view this content.
    |
    Last edited by mikerickson; 07-19-2014 at 08:54 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    07-19-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    2

    Re: Array of Ranges to work out average value PROBLEM!

    I tried your code

    Please Login or Register  to view this content.
    It does the job. Can you explain how this works? for future reference

    **** EDIT

    Both solutions solved the problem. Thank you.
    Last edited by AndresJanes; 07-19-2014 at 09:05 PM.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Array of Ranges to work out average value PROBLEM!

    It puts a formula in each cell. The cute part isn't the use of VBA, but using INDEX with the row argument set to 0 to return a whole column of the range of the array.

    INDEX(anArray, 0, x) returns the x'th column of anArray
    INDEX(anArray, y, 0 ) returns the y'th row of anArray.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Formula to work out the average of an array from a changing cell
    By francesc in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-06-2014, 10:00 PM
  2. Array problem with Average
    By bronsonb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2011, 02:09 PM
  3. Average & Min Function Problem in Array Formula
    By mubashir aziz in forum Excel General
    Replies: 8
    Last Post: 05-20-2009, 02:07 AM
  4. select variables ranges, copy to array, paste the array in new workbook
    By Mathew in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-01-2005, 05:06 AM
  5. Array Problem - Ranges
    By TonyRowland in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-24-2005, 05:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1