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.

# Averaging a Non-Contiguous Range

by Allen Wyatt
(last updated June 8, 2018)

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.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Inserting the Edit Time

One of the things that Word keeps track of is how long, in minutes, you've been editing your current document. This ...

Discover More

Borders on Multiple Paragraphs with Differing Indents

When you place a border around a paragraph, the position of that border is determined, partially, by the indent with ...

Discover More

Cookies can be a good thing, but they can also be aggravating. Here's a high-level explanation about a specific type of ...

Discover More

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!

##### More ExcelTips (ribbon)

Averaging the Last Numbers in a Column

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

Discover More

An Average that Excludes Zero Values

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

Discover More

Excluding Values from Averaging

Calculating 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
##### Subscribe

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

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven less than 9?

2017-12-08 01:12:09

Samuel

If I have values in the following cells :B1,D1,F1,H1, & J1 and want excel to find the sum of the first three smallest values in any of the cells without considering the other cells left in the range (i.e A1,C1,E1,G1), in the calculation,
what formula will I have to use?

2017-12-05 19:20:10

JV

This worked perfectly and was exactly what I was looking for. I was trying to use AVERAGEIF with non-contiguous cells (and failing miserably)--I'm grateful you figured out this work-around.

2017-10-13 09:38:31

RMK

I used this to average all cells that contain numbers AND are greater than zero.B22 C22 D22 E22 F22 G22 H22 I22 J22 K22Minutes 0 Minutes 325 Minutes 445 Minutes 425 Minutes 50=SUM(C22:K22)/SUMPRODUCT(--(C22:K22<>0),ISNUMBER(C22:K22)*1)=(0+325+445+425+50)/(4)=311.25=Average(E22, G22, I22, K22)=311.25I'm learning how to use SumProduct and it's quite handy.

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

To record a late answer for "kw" the brackets around first cells addition probably haven't been entered as in =(A1+C1+E1+G1+J1)

2017-03-17 13:39:22

kw

This doesn't work at all. By your formula the average of 3 values "90, 90, 0" would be 180/180 = 100% When the actual answer should be 180/2=90

2017-01-27 15:36:26

Phil Pilkington

Thank you so much for your trick with replacing the AVERAGEIF function! I saw so many attempted solutions to this problem and none of them work as easily or elegantly as this!

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

I never had to average non-contiguous cells and disclude 0% averages from my total average. Thanks for having this here. Very quick solution when I needed one!

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

How can this be done on Google sheets? I can't figure it out and the formula posted here doesn't work on Google sheets.

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

MAUREEN

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

This solution is very clever and works great for larger data sets.

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

2014-08-29 17:17:05

John

Nice fix, but only works if you have a small number of cells involved. For large quantities of data, makes it very difficult.

2014-06-19 11:42:47

Luke

2013-09-20 18:42:56

deanna hall

I love you! Amazing tip. What if I only wanted to count cells that contained a number including 0 but if it was blank then do not count?

2013-08-18 11:22:47

Michael (Micky) Avidan

If I understoot, correctly' the situatuion - the 4 cells: B1,D1,F1,H1,I1 can be empty and/or hold zero(s).
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!

##### This Site

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.