CountIFS with Multiple Criteria

GMC The Macro Man

Board Regular
Joined
Mar 23, 2023
Messages
104
Office Version
  1. 2021
Platform
  1. Windows
Hi there,
Could someone please help me with this formula. I need to count the number of times a number or letter appears in columns C, E & G based on the CLASS in K2.
The attached sheet shows a number of students and their class and in columns C,E & G they have a value which I need to be totaled and entered in to cells N2:Q2
I would normally just take this as a range but its proving difficult as i only want these specific columns

Any help would be appreciated
GMC

Book1
ABCDEFGHIJKLMNOPQ
1NameClassH1H2T1T2R1R2123M
2AidanP118M61WCLASSP3COUNT3443
3AmeliaP22BM51S
4AndrewP33C391
5AvaP4M82H24
6ClaraP1171U2K2 = CHOOSE CLASS
7DillonP221A334N2:Q2 =COUNT COLUMNS C,E and G
8EmilyP33M1
9FreddieP4M23
10GeorgieP1M3M227
11JacobP225M2
12KaidenP33T11M3
13KaylaP4M1MA
14LaylaP11141A
15LenaP23821
16MatthewP3282G2M
17MillieP4MMT1
18QuinnP11B3ME
19RuaridhP22CMJ3E
20SamP3M233
21SaoirseP4M2P3
22
23
Sheet1
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
how about
=COUNTIFS($C$2:$C$21,N$1,$B$2:$B$21,$K$2)+COUNTIFS($E$2:$E$21,N$1,$B$2:$B$21,$K$2)+COUNTIFS($G$2:$G$21,N$1,$B$2:$B$21,$K$2)

BUT i make "3" result 5

maybe a better way with 2021 using filter() or let() maybe

Book6
ABCDEFGHIJKLMNOPQ
1NameClassH1H2T1T2R1R2123M
2AidanP118M61WCLASSP3COUNT3443
3AmeliaP22BM51S3453
4AndrewP33C391
5AvaP4M82H24
6ClaraP1171U2K2 = CHOOSE CLASS
7DillonP221A334N2:Q2 =COUNT COLUMNS C,E and G
8EmilyP33M1
9FreddieP4M23
10GeorgieP1M3M227
11JacobP225M2
12KaidenP33T11M3
13KaylaP4M1MA
14LaylaP11141A
15LenaP23821
16MatthewP3282G2M
17MillieP4MMT1
18QuinnP11B3ME
19RuaridhP22CMJ3E
20SamP3M233
21SaoirseP4M2P3
Sheet1
Cell Formulas
RangeFormula
N3:Q3N3=COUNTIFS($C$2:$C$21,N$1,$B$2:$B$21,$K$2)+COUNTIFS($E$2:$E$21,N$1,$B$2:$B$21,$K$2)+COUNTIFS($G$2:$G$21,N$1,$B$2:$B$21,$K$2)
 
Upvote 1
Another option
Excel Formula:
=SUMPRODUCT(($B$2:$B$100=$K$2)*(RIGHT($C$1:$H$1)="1")*($C$2:$H$100=N1))
 
Upvote 1
Another option
Excel Formula:
=SUMPRODUCT(($B$2:$B$100=$K$2)*(RIGHT($C$1:$H$1)="1")*($C$2:$H$100=N1))
Hi Fluff
I'm not getting the RIGHT function to work and that's probably because I changed the Column Headers to something more simplistic for this exercise but not realizing it would have an effect on the outcome.
The attachment details the correct headers for C, E, & G. Would this change the formula?

Book1
ABCDEFGHIJKLMNOPQ
1NameClassHWBAL1HWB1T&LAL1T&L1RAL1R1123M
2AidanP118M61WCLASSP3COUNT3453
3AmeliaP22BM51S
4AndrewP33C391
5AvaP4M82H24
6ClaraP1171U2K2 = CHOOSE CLASS
7DillonP221A334N2:Q2 =COUNT COLUMNS C,E and G
8EmilyP33M1
9FreddieP4M23
10GeorgieP1M3M227
11JacobP225M2
12KaidenP33T11M3
13KaylaP4M1MA
14LaylaP11141A
15LenaP23821
16MatthewP3282G2M
17MillieP4MMT1
18QuinnP11B3ME
19RuaridhP22CMJ3E
20SamP3M233
21SaoirseP4M2P3
22
Sheet1
 
Upvote 0
looks like AL1 is unique to those 3 columns
maybe
=SUMPRODUCT(($B$2:$B$100=$K$2)*(RIGHT($C$1:$H$1,3)="AL1")*($C$2:$H$100=N1))

Book1
ABCDEFGHIJKLMNOPQ
1NameClassHWBAL1HWB1T&LAL1T&L1RAL1R1123M
2AidanP118M61WCLASSP3COUNT3453
3AmeliaP22BM51S3453
4AndrewP33C391
5AvaP4M82H24
6ClaraP1171U2K2 = CHOOSE CLASS
7DillonP221A334N2:Q2 =COUNT COLUMNS C,E and G
8EmilyP33M1
9FreddieP4M23
10GeorgieP1M3M227
11JacobP225M2
12KaidenP33T11M3
13KaylaP4M1MA
14LaylaP11141A
15LenaP23821
16MatthewP3282G2M
17MillieP4MMT1
18QuinnP11B3ME
19RuaridhP22CMJ3E
20SamP3M233
21SaoirseP4M2P3
22
23
Sheet1
Cell Formulas
RangeFormula
N3:Q3N3=SUMPRODUCT(($B$2:$B$100=$K$2)*(RIGHT($C$1:$H$1,3)="AL1")*($C$2:$H$100=N1))
 
Upvote 1
Solution
looks like AL1 is unique to those 3 columns
maybe
=SUMPRODUCT(($B$2:$B$100=$K$2)*(RIGHT($C$1:$H$1,3)="AL1")*($C$2:$H$100=N1))

Book1
ABCDEFGHIJKLMNOPQ
1NameClassHWBAL1HWB1T&LAL1T&L1RAL1R1123M
2AidanP118M61WCLASSP3COUNT3453
3AmeliaP22BM51S3453
4AndrewP33C391
5AvaP4M82H24
6ClaraP1171U2K2 = CHOOSE CLASS
7DillonP221A334N2:Q2 =COUNT COLUMNS C,E and G
8EmilyP33M1
9FreddieP4M23
10GeorgieP1M3M227
11JacobP225M2
12KaidenP33T11M3
13KaylaP4M1MA
14LaylaP11141A
15LenaP23821
16MatthewP3282G2M
17MillieP4MMT1
18QuinnP11B3ME
19RuaridhP22CMJ3E
20SamP3M233
21SaoirseP4M2P3
22
23
Sheet1
Cell Formulas
RangeFormula
N3:Q3N3=SUMPRODUCT(($B$2:$B$100=$K$2)*(RIGHT($C$1:$H$1,3)="AL1")*($C$2:$H$100=N1))

Hi etaf
Yes that is correct, the AL1 are unique to these 3 columns and when i followed the formula above, it worked great except for "Q2" as the value here is a letter (M) which needs the number of instances counted.
Is there a different formula to count letters?
 
Upvote 0
should work
=SUMPRODUCT(($B$2:$B$100=$K$2)*(RIGHT($C$1:$H$1,3)="AL1")*($C$2:$H$100=N$1))
maybe a $ infromt of 1 , in case you are copying down at all
also
is there a space before or after the M
as you can see it worked in my example and Fluff posted
 
Upvote 1
Spot on etaf, there was a space before the M. I should have seen that :rolleyes:
Thanks to you and Fluff for your help
GMC
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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