+ Reply to Thread
Results 1 to 6 of 6

Calculate average when some cells contain text

  1. #1
    Registered User
    Join Date
    09-07-2020
    Location
    Brussels
    MS-Off Ver
    Professional Plus 2016
    Posts
    14

    Calculate average when some cells contain text

    I need to calculate a simple average from some cells. However, some of these cells (not all) contain some text. Specifically, all cells contain a decimal number in between 0.0 and 10.0, while some may also contain an asterisk, e.g. 3.5*.

    How do I get to ignore the asterisk and thus include those cells in the calculation of the average? I tried with LEFT, but this would work only if all cells contained the asterisk.

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,052

    Re: Calculate average when some cells contain text

    you can use:

    =AVERAGE(INDEX(LEFT($A3:$E3,FIND("*",$A3:$E3&"*")-1)+0,0))

    assuming your data are in a3 to E3. You may need ; since you're in Belgium.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Registered User
    Join Date
    09-07-2020
    Location
    Brussels
    MS-Off Ver
    Professional Plus 2016
    Posts
    14

    Re: Calculate average when some cells contain text

    Thank you very much! Actually I have one addition to this: some cells contain only text, "n.a.". How do I get to skip these without getting back a #VALUE! error?

  4. #4
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Calculate average when some cells contain text

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  5. #5
    Registered User
    Join Date
    09-07-2020
    Location
    Brussels
    MS-Off Ver
    Professional Plus 2016
    Posts
    14

    Re: Calculate average when some cells contain text

    Please find attached a sample worksheet showing my problem
    Attached Files Attached Files

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,052

    Re: Calculate average when some cells contain text

    Can you have negative values? If not while this is not elegant, it works.

    =AVERAGE(IF(LEFT(SUBSTITUTE($A3:$E3,"n.a.",-1000),FIND("*",$A3:$E3&"*")-1)+0>=0,LEFT(SUBSTITUTE($A3:$E3,"n.a.",-10),FIND("*",$A3:$E3&"*")-1)+0))

    You may need ; and... you seem to be using an older version of Excel than me. So, please refer to the attached file. If the formulae are enclosed within a pair of { }, these are array formulae.

    These are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see the curly brackets { } appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...
    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. Calculate average numbers if number contains a text?
    By Mr.Castle in forum Excel General
    Replies: 3
    Last Post: 08-17-2018, 06:42 PM
  2. Replies: 5
    Last Post: 04-06-2018, 12:48 AM
  3. Calculate a weighted average based on text category
    By zbomb2000 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-27-2013, 10:07 PM
  4. VBA to Calculate Average of Cells Above, Not All Cells Contain Data
    By mfitzgerald94 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-15-2013, 07:44 PM
  5. [SOLVED] How to calculate average based on text
    By axendra12 in forum Excel General
    Replies: 10
    Last Post: 10-24-2012, 07:13 AM
  6. How do i calculate the average between cells using VBA?
    By 10121730 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-11-2012, 11:41 AM
  7. Calculate Average in VBA for specific cells
    By kapil in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-09-2010, 12:24 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