vba 如何使用 COUNT/COUNTIF 计算另一张工作表中给定范围的单元格值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26909779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:08:30  来源:igfitidea点击:

How to use COUNT/COUNTIF to count cell value of a given range in another sheet

excelexcel-vbavba

提问by vijesh paul

Sheet1 contains raw data: name (col-1), project (col-2), year.... etc (columns)
Sheet2 range (A1:A5) has the project name list

Sheet1 包含原始数据:名称 (col-1)、项目 (col-2)、年份......等(列)
Sheet2 范围 (A1:A5) 具有项目名称列表

I need the count, in sheet2 (range B1:B5), of each project in the list from sheet1.

我需要在 sheet2(范围 B1:B5)中对 sheet1 中列表中每个项目的计数。

How can I use COUNTIF to do that?

我怎样才能使用 COUNTIF 来做到这一点?

回答by Paresh J

You can use the following formula in sheet2to get the count of each projects listed in sheet1.

您可以在sheet2 中使用以下公式来获取sheet1 中列出的每个项目的计数。

=COUNTIF(Sheet1!B:B,A2)

Lets take a look of how to implement the above formula.

让我们来看看如何实现上述公式。

Lets say you have following data in your Sheet1. Check the below image:

假设您的Sheet1 中有以下数据。检查下图:

Sheet1 Sample Data

Sheet1 示例数据

Now, lets take a look how to enter the formula to get the count in sheet2. Check the below image:

现在,让我们看看如何输入公式以获取 sheet2 中的计数。检查下图:

Sheet2

表 2

As you can use the formula enter in cell B2of sheet2. Using COUNTIF you can get the count of projects in sheet1

您可以使用公式在sheet2 的单元格B2中输入。使用 COUNTIF 您可以获得sheet1 中的项目数