简体   繁体   English

Excel 2007-计算多个工作表中的唯一值

[英]Excel 2007 - Counting Unique Values Across Multiple Worksheets

I put together a monthly report that includes a column with unique names. 我整理了一份月度报告,其中包括一列具有唯一名称的列。 I use a formula to count the number of unique names listed each month (For example, if there were three entries for Smith, Sarah and two for Jones, Martha, the formula would give me 2 as a result). 我使用一个公式来计算每个月列出的唯一名称的数量(例如,如果Smith和Sarah有3个条目,Jones和Martha有2个条目,那么该公式将给我2个结果)。 The formula I use is =SUMPRODUCT((B5:B46<>"")/COUNTIF(B5:B46,B5:B46&"")) and it works beautifully. 我使用的公式是=SUMPRODUCT((B5:B46<>"")/COUNTIF(B5:B46,B5:B46&"")) ,效果很好。 The list is, and has to remain, sorted by date, not name. 该列表是(并且必须保留)按日期而不是名称排序。

With the end of the year approaching, I'd like to put together an annual summary, including a count of how many unique names appeared throughout the year. 随着今年年底的临近,我想整理一份年度总结,其中包括一整年中出现了多少个独特的名字。 I have this set up as a workbook, with separate sheets for each month. 我将其设置为工作簿,每个月都有单独的工作表。 What I am looking for is a method for counting unique names that appear across these twelve sheets (so that, if there was one entry each for Smith, Sarah and Jones, Martha in January, and two for Smith, Sarah and one for Jones, Martha in February, I would still get 2 as my result). 我要寻找的是一种计算出现在这十二个工作表中的唯一名称的方法(因此,如果一月份,史密斯,莎拉和琼斯,玛莎各有一个条目,史密斯,莎拉有两个条目,而琼斯有一个条目,玛莎(Martha),在2月份,我仍然会得到2

I've researched, but all I'm finding are ways to count how many times a specific name appears, not how many unique names there are. 我已经进行了研究,但是我发现的是一种方法来计算特定名称出现的次数,而不是唯一名称的数量。 I've done a little experimenting, to see if I could figure it out, but I am clearly out of my league. 我做了一些实验,看看是否可以解决,但我显然不在同盟之列。 Willing to use and try anything, but I can't install any programs or add-ons without a ridiculous process to get approval, which generally takes months, so I would like to avoid that. 愿意使用和尝试任何东西,但是如果没有一个可笑的过程来获得批准,我将无法安装任何程序或附加组件,这通常需要几个月的时间,所以我想避免这种情况。

Assuming all the names are in one column and sorted. 假设所有名称都在一列中并排序。

You can start from the first cell and compare if this cell equals the previous cell (which is none because there is no previous). 您可以从第一个单元格开始,然后比较此单元格是否等于前一个单元格(因为没有前一个单元格,所以没有)。

Going forward if the name that appears in the next cell is the same as previous, do not add 1 to the sum. 如果下一个单元格中出现的名称与以前的名称相同,则不要将其加1。 If it is different, add 1 to the sum and proceed further. 如果不同,则将总和加1,然后继续进行。

At the end the sum will contain the number of unique names. 最后,总和将包含唯一名称的数量。

Perform on every spreadsheet. 在每个电子表格上执行。 If you want it automated across multiple spreadsheets you will have to go into Visual Basic or record a macro where you go and perform this action for all spreadsheets. 如果要跨多个电子表格自动执行此操作,则必须进入Visual Basic或在其中记录宏,然后对所有电子表格执行此操作。

Is pasting all names on one sheet an option? 是否可以将所有名称粘贴在一张纸上? If so, paste all the names from 12 sheets into the same column on separate sheet, once done, just create a pivot table from it adding names as column labels, this will give you a list of all unique names across 12 months, so just do a counta formula on this list subtracting header and total row and there's your answer. 如果是这样,请将12个工作表中的所有名称粘贴到单独工作表的同一列中,一旦完成,只需从中创建一个数据透视表,然后将名称添加为列标签,这将为您提供12个月内所有唯一名称的列表,因此在此列表上做一个counta公式,减去标题和总行,即可得到答案。

EDIT here's the code as promised to compile the list quickly: 编辑以下是承诺快速编译列表的代码:

Sub compile()

ws = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

Sheets("Summary").Range("A1", Range("A1000000").End(xlUp)).ClearContents

For Each sh In ws
   Sheets(sh).Select
   Sheets(sh).Range("A2", Range("A1000000").End(xlUp)).Copy
   Sheets("Summary").Range("A1000000").End(xlUp).Offset(1, 0).PasteSpecial
Next

Sheets("Summary").Select

' End Sub 结束子

it will work as long as the amalgamated tab is called "Summary" and all the monthly tabs as per array string, which you can amend to what your actual tab names are. 只要将合并的选项卡称为“摘要”,并且所有每月选项卡都按数组字符串运行,它就可以工作,您可以将其修改为实际的选项卡名称。 it will copy all data from each of the 12 sheets from column "A" starting from cell "A2" and paste under each other on the "Summary" tab. 它将从单元格“ A2”开始复制“ A”列中的12张纸中的所有数据,并粘贴在“摘要”选项卡上。 Please note this will not work in Excel 2003, if you have Excel 2003, just change all "A1000000" references to "A65500" 请注意,这在Excel 2003中不起作用,如果您有Excel 2003,只需将所有“ A1000000”引用更改为“ A65500”

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

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