**Please Note: **
This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), *this tip may not work for you*. For a version of this tip written specifically for earlier versions of Excel, click here: Averaging a Non-Contiguous Range.

Tom needs to average a series of non-contiguous cells, excluding any cells that may contain zero values. Specifically, he needs to average cells A1, C1, E1, G1, and J1, but only counting those cells that don't contain zero.

Before getting into what works, let's take a look at what doesn't work. First of all, it doesn't work to simply add the cells and divide by 5; that doesn't take zero values into account. Second, it doesn't work to use COUNTIF in the denominator of your formula, as shown here:

=(A1+C1+E1+G1+J1) / COUNTIF(A1:J1,"<>0")

This doesn't work because it examines and counts cells within the entire range of A1:J1, not just the five cells you want considered in the average. You might also think that you could select your five non-contiguous cells, give them a name, and then use the name in your formula. While Excel allows you to create the name, the following gives an error:

=SUM(MyCells) / COUNTIF(MyCells,"<>0")

It appears that COUNTIF will only work with a single contiguous range, so the non-contiguous nature of the MyCells range throws the function into a tailspin. A similar problem occurs if you try to use a non-contiguous range with the AVERAGEIF function:

=AVERAGEIF(MyCells, "<>0")

Since you can't use any of the functions you might want to use, you are left to rely on a bit longer formula to calculate the average. You can calculate the average of these five cells by applying a bit of "trickery" to your denominator, in this manner:

=(A1+C1+E1+G1+J1) / ((A1<>0)+(C1<>0)+(E1<>0)+(G1<>0)+(J1<>0))

The evaluation done on each cell in the denominator returns either a 1 (for True) or a 0 (for False) depending on whether the cell contains a non-zero value or not. This series of values is added together, providing the necessary count of non-zero cells for the denominator.

Notice that the discussion here has been all about the denominator in the formula, not the numerator. The reason is simple—you can add all five values into the numerator; zero values there don't really matter. The only place they matter is in the denominator, which is what makes calculating this average so tricky.

*ExcelTips* is your source for cost-effective Microsoft Excel training.
This tip (7845) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: **Averaging a Non-Contiguous Range**.

**Program Successfully in Excel!** John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out *Excel 2013 Power Programming with VBA* today!

Need to calculate a running average for the last twelve values in a constantly changing range of values? The formula ...

Discover MoreExcel allows you to use functions and formulas to analyze your data. One way you can analyze your data is to use the ...

Discover MoreCalculating an average of a group of numbers is easy. What if you want to exclude a couple of the numbers from the group ...

Discover More**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

2017-12-08 01:12:09

Samuel

what formula will I have to use?

2017-12-05 19:20:10

JV

2017-10-13 09:38:31

RMK

2017-07-31 10:58:09

M.

Nice tip. But wouldn't having all elements being averaged = 0 produce a divide by 0 error?

2017-07-31 03:05:56

Kevin

2017-03-17 13:39:22

kw

2017-01-27 15:36:26

Phil Pilkington

2017-01-23 20:56:18

Shannon

Thanks very much for this! really needed this tip.

2017-01-11 12:08:18

Ryan Zbojovsky

Just thank you. Your site is unbelievably educational.

2016-12-30 15:54:11

Kevin Wampler

2016-11-09 18:06:57

Alan

I would use this much simpler method:

=AVERAGEIF(A1:J1,">0")

2016-10-29 21:39:06

Sean

2016-10-19 23:12:11

Guy

It does not work. I have double checked it. I get a 0 return. Working with 15 non-contiguous cells.

2016-10-18 11:30:41

Troy

How would i do this throwing out any cells that are below a certain percentage of the highest cell?

2016-07-31 15:59:13

Frank

Thank you for the understandable example.

2016-05-27 09:18:36

Thank you! I searched all over for this answer. You had the best explanation!

2015-12-29 20:56:05

Taylor

Thank you soooo much!!!!

2014-12-29 16:17:52

Ed

https://colinlegg.wordpress.com/2013/05/04/conditional-average-on-non-contiguous-ranges-using-frequency/

2014-08-29 17:17:05

John

2014-06-19 11:42:47

Luke

Super helpful, thanks so much.

2013-09-20 18:42:56

deanna hall

2013-08-18 11:22:47

Michael (Micky) Avidan

If this is the case -the formulas, shown in the following link are shorter than the suggested in the tip:

http://tinypic.com/r/j0lj40/5

Michael Avidan

“Microsoft®” MVP – Excel

ISRAEL

2013-08-17 09:53:11

Taty

Great! I was just looking for something like this. Thanks.

2013-07-13 21:51:47

Juan

Wow, very interesting tip, amazing!

Got a version of Excel that uses the
ribbon interface (Excel 2007 or later)?
**This site is for you!** If you
use an earlier version of Excel, visit
our *ExcelTips* site focusing on the menu interface.

**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

Copyright © 2018 Sharon Parq Associates, Inc.

## Comments