+ Reply to Thread
Results 1 to 8 of 8

Disregard Changing Null Values so Average can be Taken

  1. #1
    Registered User
    Join Date
    07-29-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2007
    Posts
    35

    Disregard Changing Null Values so Average can be Taken

    Hello,

    I am working with a dynamic data set from which I need to calculate averages.

    After downloading the "Example" worksheet", you will see that in Sheet2 I have two sets of data. This is from a database that I periodically load. At the moment, there are no values for "Grapes" or "Bananas". Consequently, I cannot take the average quality of nothing (see Sheet1). Only when I comment out the ".AverageIfs(a, b, "Grapes/Bananas")" in my VBA code does it work.

    However, I cannot do this forever because I later on might have Grapes or Bananas values.
    I have tried using:

    Please Login or Register  to view this content.
    I have tried a similar IfError statement in an Excel cell and it worked.

    I would appreciate any ideas to skip the null value SOMETIMES. And, if I would love ideas that do not resort to coding around every single fruit.

    Thanks!
    Kevin
    Attached Files Attached Files
    Last edited by kchen; 08-18-2010 at 04:21 PM.

  2. #2
    Registered User
    Join Date
    07-29-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Disregard Changing Null Values so Average can be Taken

    Also, the error that I get is:

    If you run the code in vba,
    Run-time Error '1004': Application-defined or object-defined Error

    If you hit the button,
    Run-time Error '1004': Unable to get the AverageIfs property of the WorksheetFunction class

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Disregard Changing Null Values so Average can be Taken

    It would be worth reconsidering the approach but to answer the specific question...

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-29-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Disregard Changing Null Values so Average can be Taken

    DonkeyOte,

    Thanks for your input. This method works well, but I don't find it ideal.

    In my actual worksheet, I have 20 or so "_Len" and "_Rate" objects and I would prefer to not have too many lines of code (which is what the "If, then" statements would require).

    Thanks again,
    kchen

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Disregard Changing Null Values so Average can be Taken

    Per the earlier note - you should revise your approach.

    If the criteria values in the Summary table reflect the values in the Source table (ie consistent) you can just apply the formulae to the ranges en masse and subsequently apply results.

    Using your sample file:

    Please Login or Register  to view this content.
    Your VBA is then much simplified:

    Please Login or Register  to view this content.
    though why you're using VBA rather than just using formulae in cells escapes me given the fruit listing is not dynamic and the values in D are themselves populated by in cell formulae

    Anyway, I hope the above is of some use...

  6. #6
    Registered User
    Join Date
    07-29-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Disregard Changing Null Values so Average can be Taken

    For DonkeyOte and others who are curious why I'm using vba:

    In my real workbook, I have created a database with several thousand rows. Furthermore, this database is periodically updated through another program. As a result, the number of rows and the data itself never stays the same.

    More explicitly, today I have only four fruit categories with only 30 or so rows of data. Tomorrow, I might have 1000 rows of data and only two fruit categories.

    I hope my situation makes more sense.

    ...Now, I need to look into what DonkeyOte said a little more...

    Thanks,
    kchen

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Disregard Changing Null Values so Average can be Taken

    Quote Originally Posted by kchen
    I hope my situation makes more sense.
    To an extent - but the point would be the formulae you're using are not hugely expensive and are seemingly relatively limited in number (ie per "fruit").
    Leaving the formulae in place and referencing either the source columns in their entirety or using a Dynamic Named Range should not have too adverse an effect on performance.

    If you're saying you want the figures to remain unchanged when the source data updates (until such time as you invoke the sub routine) then there is obvious merit in avoiding in cell formulae.
    However, even then from a code perspective it's better (IMO) to calculate the range en masse via formulae, subsequently override the formulae with the results thereof, at which point the values become "static".
    (this being the approach outlined in the example code)

  8. #8
    Registered User
    Join Date
    07-29-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Disregard Changing Null Values so Average can be Taken

    Hey DonkeyOte,
    If you're saying you want the figures to remain unchanged when the source data updates (until such time as you invoke the sub routine) then there is obvious merit in avoiding in cell formulae.
    Yup, that's pretty much why I wanted to avoid cell formulae.

    However, I have gone ahead and tried it your way. It works for most cells, I am still figuring out some kinks. But, I think it should be good.

    At the same time, I would like to know why I am unable to use something like this (I have tried all variations:

    Please Login or Register  to view this content.
    Thanks!
    Last edited by kchen; 08-13-2010 at 01:37 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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