简体   繁体   English

当相邻列中的相应行保持特定值时,计算列中非空单元格的总和 - VBA 或公式?

[英]Count sum of non-empty cells in a column when corresponding row in an adjacent column holds specific value - VBA or formula?

Currently, I have a range ( A1:M22 ) where for each column ( A through M ) I count the number of non-empty cells at row 23.目前,我有一个范围( A1:M22 ),对于每一列( AM ),我计算第 23 行的非空单元格的数量。

I am using the COUNTBLANK function.我正在使用COUNTBLANK function。 However, not all rows are to be included in the total count at row 23 in each column.但是,并非所有行都包含在每列第 23 行的总数中。

Thus, I have added column N , where for each row I have indicated whether the specific row should be included in the count or not.因此,我添加了N列,对于每一行,我都指出了特定行是否应包含在计数中。 The sheet looks like this:工作表如下所示:

桌子图片

As indicated in column N , Person 4, Person 7 and Person 15 are not to be counted in the total of employees with a salary even though they appear in the overview.如第N列所示,第 4 人、第 7 人和第 15 人即使出现在概览中,也不计入有薪员工总数。 This is due to the fact that perform a task that isn't relevant for the total baseline.这是因为执行与总基线无关的任务。

Taking the month of February for an example, the count should be 10 instead of 12, since Person 4 and Person 7 had a salary that month but shouldn't be included in the total.以 2 月份为例,计数应该是 10 而不是 12,因为第 4 个人和第 7 个人当月有薪水,但不应计入总数。

My question is then, how do I account for this when calculating the count of employees with a salary for each month?那么我的问题是,在计算每个月有薪员工的数量时,我该如何解释这一点? Is it possible to do by an elaborate formula or is VBA the better choice?是否可以通过精心设计的公式来完成,还是 VBA 是更好的选择?

It just looks like countifs:它看起来像计数:

=COUNTIFS(C3:C22,"<>",N3:N22,"Yes")

eg for February例如二月

在此处输入图像描述

To pull the formulas across, you would need to anchor column N:要拉出公式,您需要锚定列 N:

=COUNTIFS(C3:C22,"<>",$N3:$N22,"Yes")

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

相关问题 Excel公式:列中唯一单元格的数量,IF对应的行是一定值 - Excel formula: count of unique cells in column, IF corresponding row is certain value VBA:如何将公式应用于与非空单元格相邻的单元格? - VBA: How do I apply a formula to cells adjacent to non-empty cells? VBA计算列中的连续非空单元格,从给定的一个开始:必须处理特殊情况 - VBA count consecutive non-empty cells in a column, starting from a given one: must handle special cases 带有条件的表的每一列中有C​​OUNT个非空单元格 - COUNT non-empty cells in each column of a table with condition EXCEL-按唯一列值计算非空行的数量 - EXCEL - count number of non-empty rows by unique column value 一列中非公式单元格的计数 - Count of Non Formula Cells in a column 代码以找到excel列中连续非空单元格的总和,直到出现空单元格? - code to find the sum of continuous non-empty cells in a column in excel till the empty cell occurs? 如果列为空,则VBA清除与列相邻的单元格 - VBA clear cells adjacent to the column if it is empty 将非空白单元格(在一列中)的值除以空单元格,删除原始行并重复 vba - Divide the value of non-blank cells (in a column) amongst empty cells, delete original row and repeat with vba 将一列的非空单元格命名为上一列的值 - Naming the non-empty cells of a column as the previous column's values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM