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. ...


Self-Deleting Macros

Macros are very powerful, but you may not want them to always be available to a user. Here are some ways you can limit ...

Discover More

Deleting a Power Management Plan

Windows allows you to create custom power management plans. When you no longer need a plan you previously defined, you ...

Discover More

Checking Lock Status of Cells

When you first create a worksheet, all the cells in that worksheet are formatted as locked. As you unlock various cells ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 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

Determining a Simple Moving Average

A moving average can be a great way to analyze a series of data points that you've collected over time. Setting up a ...

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

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

View most recent newsletter.


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 five minus 4?

2017-12-08 01:12:09


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


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


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


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

2017-07-31 03:05:56


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


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


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


I would use this much simpler method:

2016-10-29 21:39:06


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


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


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


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


Thank you soooo much!!!!

2014-12-29 16:17:52


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

2014-08-29 17:17:05


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


Super helpful, thanks so much.

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:

Michael Avidan
“Microsoft®” MVP – Excel

2013-08-17 09:53:11


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

2013-07-13 21:51:47


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.

Newest Tips

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.