+ Reply to Thread
Results 1 to 6 of 6

[Office 365] Excel VBA: Average range, but ignore cells with test.

  1. #1
    Registered User
    Join Date
    01-25-2021
    Location
    Lexington, KY
    MS-Off Ver
    Office 2019, Office 365
    Posts
    2

    [Office 365] Excel VBA: Average range, but ignore cells with test.

    Good morning everyone. I'm working on an Excel item for audit data, and I'm trying to dynamically calculate a weekly average. Each Cell in the column range will contain the following: a number, a comma-separated listed of numbers, or the words No data.

    I found the ave_range function on this forum, but when applying to a range that has text, it returns an error.

    I am not the best with VBA, so I was hoping someone might have input on how to alter the below VBA formula to ignore cells with the words 'No data' in them. I specifically do not want them to be treated as 0, as 0 is a valid numerical entry to average.

    Please Login or Register  to view this content.
    Many thanks in advance!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: [Office 365] Excel VBA: Average range, but ignore cells with test.

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation with manually calculated results, explaining which information is data and which is results, and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

    To upload a file click the Go Advanced button at the foot of your post, look underneath the post area for the Manage Attachments section and take it from there.

    That said why do you need VBA to do this
    On the face of it and without seeing the workbook, standard Excel functions would seem the natural way to obtain the average.

    Untested in the absence of a workbook but perhaps

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: [Office 365] Excel VBA: Average range, but ignore cells with test.

    Your code does not split comma-delimited entries.
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: [Office 365] Excel VBA: Average range, but ignore cells with test.

    This should do what you want:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-25-2021
    Location
    Lexington, KY
    MS-Off Ver
    Office 2019, Office 365
    Posts
    2

    Re: [Office 365] Excel VBA: Average range, but ignore cells with test.

    Please see the attached workbook.

    I could not figure out a function-based solution to allow for columns containing comma-delimited values to average properly; it would only average in the last number, and due to organizational needs I can't separate them into helper columns without rewriting other parts of the data.

    The VBA I found solved the issue entirely, except for the cells that have text.

    Quote Originally Posted by Bernie Deitrick View Post
    Your code does not split comma-delimited entries.
    The code that I posted calculates the averages properly. I compared them to a manual count using a helper column. It doesn't need to 'split' them, it just needs to calculate them all separately into the average.

    Also thank you for your code. I'm testing it to see if it works, and it does ignore the 'no data' entries. Looks like it's working fine for what I needed, thank you very much!
    Attached Files Attached Files
    Last edited by elmerg99; 01-25-2021 at 12:19 PM.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: [Office 365] Excel VBA: Average range, but ignore cells with test.

    "Splitting" in this context means to separate the numbers using a delimiter, to allow the code to find the numbers used for the average/

    Your file with my code and a checking area....
    Attached Files Attached Files

+ 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. Need help with a formula to average a range, ignore blanks but NOT zeros
    By Stryfe in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-30-2020, 04:54 PM
  2. Average non-contiguous cells, ignore blank cells and avoid #DIV/0!
    By Davdef in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 10-06-2018, 10:03 AM
  3. Replies: 14
    Last Post: 06-14-2013, 09:00 PM
  4. Average the last 10 cells of a dynamic column but ignore blank cells & 0
    By mattadler22 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-13-2013, 11:37 PM
  5. When using AVERAGE function, ignore cells with certain values
    By eheruty in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 01-18-2013, 04:30 PM
  6. Replies: 0
    Last Post: 12-23-2011, 06:55 AM
  7. [SOLVED] How do I ignore cells with errors when calculating an average?
    By M Enfroy in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-01-2005, 04:09 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