简体   繁体   中英

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.

I am using the COUNTBLANK function. However, not all rows are to be included in the total count at row 23 in each column.

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

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?

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:

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

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