countif cell contains a specific number

ivanastaylor

New Member
Joined
Apr 22, 2003
Messages
1
I have data that has more than one number in a cell - separated by a comma. i.e. 23,2

I want to count how many times 2 occurs either alone in a cell or as part of a cell that contains a 2 separated by a comma.

I've tried
=countif(range, 2)
=countif(range, *2*)

and didn't get anywhere - any assistance?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,869
Office Version
  1. 365
Platform
  1. Windows
Welcome to the board :biggrin:

Maybe:

=SUMPRODUCT(--ISNUMBER(FIND(",2",range)))

Regards
Jon
 

ADAMC

Well-known Member
Joined
Mar 20, 2007
Messages
1,169
Office Version
  1. 2013
Platform
  1. Windows
How about:
=COUNTIF(A:A,"**,2")
 

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
...but I don't think either of those will count a single 2 in a cell....if range is A1:A10 try

=SUMPRODUCT(--ISNUMBER(FIND(",2,",","&A1:A10&",")))
 

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,209

ADVERTISEMENT

I have data that has more than one number in a cell - separated by a comma. i.e. 23,2

I want to count how many times 2 occurs either alone in a cell or as part of a cell that contains a 2 separated by a comma.

I've tried
=countif(range, 2)
=countif(range, *2*)

and didn't get anywhere - any assistance?

C2: 2

A2:A4, the range of interest.

D2:

=SUMPRODUCT(LEN(","&$A$2:$A$4&",")-LEN(SUBSTITUTE(","&$A$2:$A$4&",",","&C2&",","")))/(LEN(C2)+2)
 

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,869
Office Version
  1. 365
Platform
  1. Windows
Hi Aladin et Barry

I notice that this works but I don't understand why. What is the purpose of the "," ?

Jon
 

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,209
Hi Aladin et Barry

I notice that this works but I don't understand why. What is the purpose of the "," ?

Jon

In order to pick up a leading and/or trailing 2...

2,3,4
2
3,42,2
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,102
Messages
5,768,104
Members
425,454
Latest member
khoro

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
Top