简体   繁体   中英

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). The formula I use is =SUMPRODUCT((B5:B46<>"")/COUNTIF(B5:B46,B5:B46&"")) and it works beautifully. 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).

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. If it is different, add 1 to the sum and proceed further.

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.

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.

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. Please note this will not work in Excel 2003, if you have Excel 2003, just change all "A1000000" references to "A65500"

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