简体   繁体   中英

Excel formula: make the average depending on a cell

I want to make a formula that turns in a VBA code that makes the average for column A even though there are some 0 there. I want to divide it by a the number in a cell that counts the objects in column A.

在此处输入图像描述

I used to use this formula, but it divides my sum incorrectly because I have 0's (I want to keep the 0's there):

=AVERAGE(Sheet1!$B$2:$B$10000)

The easiest way to do this, is to get the total of column B by using sum(B:B) (or a more specific range, if you want), and the amount of non-blank cells in column A by using counta(A:A) (in my comment I used count which only counts the amount of numbers in the range, counta should count all non-blank cells). You can then divide the former by the latter to get the number you are looking for, resulting in a formula looking something like

=SUM(B:B)/COUNTA(A:A)

If you already have the count of column A in a cell (eg E3), it's even simpler, just use something like

=SUM(B:B)/E3

You can use AverageIf for such a purpose, as you can see in my example:

Row/Column  A   B   C   D
         1
         2      2       =AVERAGE(B2:B5) => value 3
         3      4       =AVERAGEIF(B2:B5;"<>0") => value 4
         4      0
         5      6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM