CountIf with exceptions?

Gary McMaster

Well-known Member
Joined
Feb 8, 2009
Messages
1,978
Hi Everyone,

Given the sample below, how can I count how many times a given letter appears in the table with a number (or non-blank cell) in the cell to its right. In this example the answer is A=3, B=2 and everything else = 4.

I'm not having much luck trying it with CountIf. Is there something better?

Thanks for any advice.

Gary


Excel Workbook
BCDE
2A1B2
3C3D4
4E5F6
5G7H8
6I9J10
7K11L12
8B2A1
9D4C3
10F6E5
11H8G7
12J10I9
13L12K11
14AB
15C3D4
16E5F6
17G7H8
18I9J10
19K11L12
20BA1
21D4C3
22F6E5
23H8G7
24J10I9
25L12K11
Sheet1
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Excel Workbook
ABCDEF
1A1B2**
2C3D4*2
3E5F6*3
4G7H8**
5I9J10**
6K11L12**
7B2A1**
8D4C3**
9F6E5**
10H8G7**
11J10I9**
12L12K11**
13A*B***
14C3D4**
15E5F6**
16G7H8**
17I9J10**
18K11L12**
19BA1**
20D4C3**
21F6E5**
22H8G7**
23J10I9**
24L12K11**
Sheet1
 
Upvote 0
Thanks Mike and Robert. I was able to slightly modify your formulas to fit my real data and it seems to be working.

Gary
 
Upvote 0
Hi Everyone,

Given the sample below, how can I count how many times a given letter appears in the table with a number (or non-blank cell) in the cell to its right. In this example the answer is A=3, B=2 and everything else = 4.

I'm not having much luck trying it with CountIf. Is there something better?

Thanks for any advice.

Gary


Excel Workbook
BCDE
2A1B2
3C3D4
4E5F6
5G7H8
6I9J10
7K11L12
8B2A1
9D4C3
10F6E5
11H8G7
12J10I9
13L12K11
14AB
15C3D4
16E5F6
17G7H8
18I9J10
19K11L12
20BA1
21D4C3
22F6E5
23H8G7
24J10I9
25L12K11
Sheet1
F2: A
F3: B
Etc.

G2, control+shift+enter, not just enter, and copy down:

=SUM(IF($A$2:$C$25=F2,IF(ISNUMBER($B$2:$D$24),1)))
 
Upvote 0
Thanks Aladin. I'm trying all of these suggestions. I already have this working using VBA code but I am trying to learn more about formulas. I'm still studying the formulas already posted to try and understand them. There is one more part to this that I'm hoping can also be done with formulas.

Below is what I have so far. This uses the same data shown in my original post. For each identifier in columns B & D, I would like to count the number of times its associated value (column C or D) is greater than, less than or equal to its counterpart in the other ID column. The formula I used in column J (which seems to work) is my own feeble attempt ... maybe there is a better way to do that too.

Thanks very much for all the replies so far.

Gary

Excel Workbook
HIJKLMN
3IdentPlusMinusGreaterLessEqual#Tests
4A48Col C > Col ECol CCol C = Col E4
5B844
6C12164
7D16124
8E20244
9F24204
10G28324
11H32284
12I36404
13J40364
14K44484
15L48444
16
17
18BthruD=Sheet1!$B$2:$D$25
19ColB=Sheet1!$B$2:$B$25Always contains ID
20ColC=Sheet1!$C$2:$C$25May also contain text or be blank
21ColD=Sheet1!$D$2:$D$25Always contains ID
22ColE=Sheet1!$E$2:$E$25May also contain text or be blank
23CthruE=Sheet1!$C$2:$E$25
Sheet1
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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