简体   繁体   English

Excel公式:根据单元格取平均值

[英]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.我想创建一个公式来生成一个 VBA 代码,该代码计算 A 列的平均值,即使那里有一些 0。 I want to divide it by a the number in a cell that counts the objects in column A.我想将它除以一个单元格中的数字,该单元格计算 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):我曾经使用过这个公式,但它错误地划分了我的总和,因为我有 0(我想保留 0):

=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).最简单的方法是使用sum(B:B) (或更具体的范围,如果需要)获取 B 列的总数,并使用counta(A:A) (在我的评论中,我使用了count ,它只计算范围内的数字数量, counta应该计算所有非空白单元格)。 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如果您已经在单元格中计算了 A 列(例如 E3),则更简单,只需使用类似

=SUM(B:B)/E3

You can use AverageIf for such a purpose, as you can see in my example:您可以为此目的使用AverageIf ,如您在我的示例中所见:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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