Counting names based on their department

Nutmegger

New Member
Joined
Dec 14, 2022
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I have a workbook where people's names are entered into (A2:U30)
The names that are allowed to be entered are validated against a list of names in (G1:G50);
Each name has a corresponding department in (H1:H50); There are 4 different departments, so each person belongs to 1 of the 4 departments.

I am looking for a formula that will give me a count of how many people entered in (A2:U30) represent each of the 4 departments.
In other words, I want to get 4 formulas in 4 cells showing something like this:

Accounting: 5
Sales: 12
Service: 20
HR: 8

I hope someone can help - thank you in advance!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi & welcome to MrExcel.
Can you post some sample data, along with expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Hi,
Re-writing the coordinates a bit, and attaching a sample:
I have a workbook where people's names are entered into (D2:J30)
The names that are allowed to be entered are validated against a list of names in (M2:M51) (Validation not used in the sample spreadsheet)
Each name has a corresponding department listed in (N2:N51); There are 4 different departments, so each person belongs to 1 of the 4 departments.

I am looking for a formula that will give me a count of how many people entered in (D2:J30) represent each of the 4 departments.
In other words, I want to get 4 formulas in 4 cells showing something like this:

Accounting: 5
Sales: 12
Service: 20
HR: 8

Sample.xlsx
ABCDEFGHIJKLMNO
1SunMonTueWedThurFriSatNamesDepartment
2Alfonso TorresAccounting
3I would like to automate this part:Arabella VaughanHR
4Beckett FergusonHR
5Representation by deptNumbersCharlee BlackwellBroderick GalvanService
6HR12Elise BarryBrynn ScottHR
7Accounting6Carly NobleTalent
8Sales9Carolyn IbarraService
9Service11Carolyn IbarraCharlee BlackwellHR
10Cristian HunterHR
11Hayley AveryArabella VaughanYahir BenderDamion RushAccounting
12Makayla VazquezJake DickersonCristian HunterDemarion MorganHR
13Gavin PotterShawn OwensElise BarryAccounting
14Isla VanceJoselyn RiosEsmeralda OrrService
15Hayley AveryDemarion MorganDemarion MorganGavin PotterService
16Kayden LeonJaylin McphersonGeovanni AllisonSales
17Katie YatesWade MullenHayden CoffeySales
18Scarlett WeaverHayley AverySales
19Peyton HarveyHazel CaseyAccounting
20Isla VanceService
21Broderick GalvanJadyn GoldenHR
22Geovanni AllisonJake DickersonAccounting
23Hazel CaseyJavier BishopService
24Matias RichardJayda SweeneyHR
25Johnathan ShepardJaylin McphersonAccounting
26Charlee BlackwellJohnathan ShepardHR
27Joselyn RiosTalent
28Kaitlin UnderwoodHR
29Katie YatesSales
30Kayden LeonService
31Keith FinleyService
32Maggie OnealHR
33Makayla VazquezHR
34Marlon McmahonHR
35Matias RichardSales
36Natalia MejiaService
37Peyton HarveySales
38Reina DavidsonAccounting
39Rory MorrowSales
40Ryder HoltHR
41Sanai MataHR
42Scarlett WeaverAccounting
43Shawn OwensAccounting
44Shelby BurnettSales
45Talon AustinSales
46Terry MolinaService
47Thomas SuttonAccounting
48Tomas LiuSales
49Ty McintyreHR
50Wade MullenSales
51Yahir BenderSales
52
Sheet1
 
Upvote 0
There's probably a more elegant solution than this, but if you're OK using a helper column (I've used column C here but it could be anywhere there's a clear column, and you can hide it if you want) then the following seems to work for what you want. I note you have 365 so hopefully the TOCOL() function is available to you. Enter the VLOOKUP/TOCOL formula into cell C6, and then a straightforward COUNTIF() referencing the spill range in B6:B9.

count.xlsx
ABCDEFGHIJKLMN
1SunMonTueWedThurFriSatNamesDepartment
2Alfonso TorresAccounting
3I would like to automate this part:Arabella VaughanHR
4Beckett FergusonHR
5Representation by deptNumbersCharlee BlackwellBroderick GalvanService
6HR8HRElise BarryBrynn ScottHR
7Accounting6AccountingCarly NobleTalent
8Sales8ServiceCarolyn IbarraService
9Service5SalesCarolyn IbarraCharlee BlackwellHR
10HRCristian HunterHR
11SalesHayley AveryArabella VaughanYahir BenderDamion RushAccounting
12HRMakayla VazquezJake DickersonCristian HunterDemarion MorganHR
13AccountingGavin PotterShawn OwensElise BarryAccounting
14HRIsla VanceJoselyn RiosEsmeralda OrrService
15ServiceHayley AveryDemarion MorganDemarion MorganGavin PotterService
16AccountingKayden LeonJaylin McphersonGeovanni AllisonSales
17ServiceKatie YatesWade MullenHayden CoffeySales
18TalentScarlett WeaverHayley AverySales
19SalesPeyton HarveyHazel CaseyAccounting
20HRIsla VanceService
21HRBroderick GalvanJadyn GoldenHR
22ServiceGeovanni AllisonJake DickersonAccounting
23AccountingHazel CaseyJavier BishopService
24SalesMatias RichardJayda SweeneyHR
25SalesJohnathan ShepardJaylin McphersonAccounting
26AccountingCharlee BlackwellJohnathan ShepardHR
27SalesJoselyn RiosTalent
28ServiceKaitlin UnderwoodHR
29SalesKatie YatesSales
30AccountingKayden LeonService
31SalesKeith FinleyService
32HRMaggie OnealHR
33HRMakayla VazquezHR
34Marlon McmahonHR
35Matias RichardSales
36Natalia MejiaService
37Peyton HarveySales
38Reina DavidsonAccounting
39Rory MorrowSales
40Ryder HoltHR
41Sanai MataHR
42Scarlett WeaverAccounting
43Shawn OwensAccounting
44Shelby BurnettSales
45Talon AustinSales
46Terry MolinaService
47Thomas SuttonAccounting
48Tomas LiuSales
49Ty McintyreHR
50Wade MullenSales
51Yahir BenderSales
52
Sheet1
Cell Formulas
RangeFormula
C6:C33C6=VLOOKUP(TOCOL($D$2:$J$36,1),$M$2:$N$51,2,FALSE)
B6:B9B6=COUNTIF($C$6#,A6)
Dynamic array formulas.
 
Upvote 0
Another option
Fluff.xlsm
ABCDEFGHIJKLMN
1SunMonTueWedThurFriSatNamesDepartment
2Alfonso TorresAccounting
3I would like to automate this part:Arabella VaughanHR
4Beckett FergusonHR
5Representation by deptNumbersCharlee BlackwellBroderick GalvanService
6HR8Elise BarryBrynn ScottHR
7Accounting6Carly NobleTalent
8Sales8Carolyn IbarraService
9Service5Carolyn IbarraCharlee BlackwellHR
10Cristian HunterHR
11Hayley AveryArabella VaughanYahir BenderDamion RushAccounting
12Makayla VazquezJake DickersonCristian HunterDemarion MorganHR
13Gavin PotterShawn OwensElise BarryAccounting
14Isla VanceJoselyn RiosEsmeralda OrrService
15Hayley AveryDemarion MorganDemarion MorganGavin PotterService
16Kayden LeonJaylin McphersonGeovanni AllisonSales
17Katie YatesWade MullenHayden CoffeySales
18Scarlett WeaverHayley AverySales
19Peyton HarveyHazel CaseyAccounting
20Isla VanceService
21Broderick GalvanJadyn GoldenHR
22Geovanni AllisonJake DickersonAccounting
23Hazel CaseyJavier BishopService
24Matias RichardJayda SweeneyHR
25Johnathan ShepardJaylin McphersonAccounting
26Charlee BlackwellJohnathan ShepardHR
27Joselyn RiosTalent
28Kaitlin UnderwoodHR
29Katie YatesSales
30Kayden LeonService
31Keith FinleyService
32Maggie OnealHR
33Makayla VazquezHR
34Marlon McmahonHR
35Matias RichardSales
36Natalia MejiaService
37Peyton HarveySales
38Reina DavidsonAccounting
39Rory MorrowSales
40Ryder HoltHR
41Sanai MataHR
42Scarlett WeaverAccounting
43Shawn OwensAccounting
44Shelby BurnettSales
45Talon AustinSales
46Terry MolinaService
47Thomas SuttonAccounting
48Tomas LiuSales
49Ty McintyreHR
50Wade MullenSales
51Yahir BenderSales
Main
Cell Formulas
RangeFormula
B6:B9B6=SUM(COUNTIFS(M:M,TOCOL($D$2:$J$30,1),N:N,A6))
 
Upvote 0
I don't think it's possible with older version of excels but definitely with vba.
VBA Code:
Sub testing1()
            Dim j, k, i As Integer
            Dim store As String
            For j = 6 To 9
                    store = 0
                    For k = 2 To 26
                                For i = 4 To 10
                                        If Cells(k, i) <> "" Then
                                                If WorksheetFunction.VLookup(Cells(k, i), Range("M:N"), 2, 0) = Range("A" & j) Then
                                                    store = store + 1
                                                    Cells(j, 2) = store
                                                End If
                                        End If
                                Next i
                    Next k
            Next j
End Sub
 

Attachments

  • 1671112654752.png
    1671112654752.png
    59.4 KB · Views: 5
Last edited:
Upvote 0
Another option
I like your formula best, I think

"=SUM(COUNTIFS(M:M,TOCOL($D$2:$J$30,1),N:N,A6))"
.... but it is not counting... the result comes up as a "0"
What did I miss?

Sample.xlsx
ABCDEFGHIJKLMNO
1SunMonTueWedThurFriSatNamesDepartment
2Alfonso TorresAccounting
3I would like to automate this part:Arabella VaughanHR
4Beckett FergusonHR
5Representation by deptNumbersCharlee BlackwellBroderick GalvanService
6HR0Elise BarryBrynn ScottHR
7Accounting0Carly NobleTalent
8Sales0Cristian HunterCarolyn IbarraService
9Service0Carolyn IbarraCharlee BlackwellHR
10Cristian HunterHR
11Hayley AveryArabella VaughanYahir BenderDamion RushAccounting
12Makayla VazquezJake DickersonCristian HunterDemarion MorganHR
13Gavin PotterShawn OwensElise BarryAccounting
14Isla VanceJoselyn RiosEsmeralda OrrService
15Hayley AveryDemarion MorganDemarion MorganGavin PotterService
16Kayden LeonJaylin McphersonGeovanni AllisonSales
17Katie YatesWade MullenHayden CoffeySales
18Scarlett WeaverHayley AverySales
19Peyton HarveyHazel CaseyAccounting
20Isla VanceService
21Broderick GalvanJadyn GoldenHR
22Geovanni AllisonJake DickersonAccounting
23Hazel CaseyJavier BishopService
24Matias RichardJayda SweeneyHR
25Johnathan ShepardJaylin McphersonAccounting
26Charlee BlackwellJohnathan ShepardHR
27Joselyn RiosTalent
28Kaitlin UnderwoodHR
29Katie YatesSales
30Kayden LeonService
31Keith FinleyService
32Maggie OnealHR
33Makayla VazquezHR
34Marlon McmahonHR
35Matias RichardSales
36Natalia MejiaService
37Peyton HarveySales
38Reina DavidsonAccounting
39Rory MorrowSales
40Ryder HoltHR
41Sanai MataHR
42Scarlett WeaverAccounting
43Shawn OwensAccounting
44Shelby BurnettSales
45Talon AustinSales
46Terry MolinaService
47Thomas SuttonAccounting
48Tomas LiuSales
49Ty McintyreHR
50Wade MullenSales
51Yahir BenderSales
52
Sheet1
Cell Formulas
RangeFormula
B6:B9B6=SUM(COUNTIFS(M:M,TOCOL($D$2:$J$30,1),N:N,A6))
 
Upvote 0
Check that you have the TOCOL function.
 
Upvote 0
Check that you have the TOCOL function.
Yep, that's what I have for the formula in B6, exactly like this:
=SUM(COUNTIFS(M:M,TOCOL($D$2:$J$30,1),N:N,A6))
But it keeps showing a "0" in the cell
 
Upvote 0
That formula works for me. If you type =to into a cell, do you get 3 possible options, or just 1?
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top