+ Reply to Thread
Results 1 to 3 of 3

Multiple Averageifs

  1. #1
    Registered User
    Join Date
    01-24-2017
    Location
    home
    MS-Off Ver
    MS Office 2016
    Posts
    46

    Multiple Averageifs

    I am trying to get the average of everything in column K but only when column C ha a particular value. It is working, but if there is no value of "NS" in column C then the whole thing just stops working. How can I get it to continue working and just accept the value doesn't exist?


    Range("O2").Value = WorksheetFunction.AverageIfs(Range("K:K"), Range("C:C"), "WTW")
    Range("O3").Value = WorksheetFunction.AverageIfs(Range("K:K"), Range("C:C"), "Fuel")
    Range("O4").Value = WorksheetFunction.AverageIfs(Range("K:K"), Range("C:C"), "NS")
    Range("O5").Value = WorksheetFunction.AverageIfs(Range("K:K"), Range("C:C"), "Expansion")
    Range("O6").Value = WorksheetFunction.AverageIfs(Range("K:K"), Range("C:C"), "Minor")

  2. #2
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Multiple Averageifs

    I'm not a VBA expert, but could this be handled with: On Error Resume Next prior to each command?

    - Moo

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Multiple Averageifs

    Hi there,

    See if the following code does what you need - it will enter a value of zero in the Average Cell if none of the tested cells contain the required value:

    Please Login or Register  to view this content.
    The highlighted values can be altered to suit your own requirements.


    I've made some changes to your code:

    (a) The Range references are now fully qualified - this means that the code is independent of whichever worksheet happens to be active

    (b) The no of rows to be conditionally averaged is specified by the value of the Constant lMAXIMUM_ROWS - it is not very efficient to require Excel to conditionally average almost one and a half million rows each time.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

+ 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] AverageIFs across multiple tabs
    By JulieKT in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-26-2015, 10:52 AM
  2. [SOLVED] AVERAGEIFS with multiple worksheets
    By a4turbo in forum Excel General
    Replies: 5
    Last Post: 08-21-2015, 08:18 AM
  3. Nesting multiple AVERAGEIFS
    By yuenk in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-13-2015, 03:22 PM
  4. [SOLVED] AVERAGEIFS with multiple criteria
    By bibu in forum Excel General
    Replies: 5
    Last Post: 03-22-2014, 03:28 PM
  5. AVERAGEIFS(), with multiple criteria
    By Jkember in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-21-2014, 06:33 PM
  6. AVERAGEIFS Multiple Criteria
    By qhoney in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-05-2014, 03:58 PM
  7. [SOLVED] AVERAGEIFS using multiple ranges and multiple criteria
    By LindsayS in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-03-2013, 01:49 PM

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