Countif in Excel

Attached I have a file for an example. Column C has long list of data such as "2, 6, 10". Column D has then just one number such as "2". I would like Column E to do a countif of total cells that say Column D's number in it. Any idea how to do this? Attached is a file
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cansevinAuthor Commented:
Would it be easier if the data was broken up into different cells? So, instead of a cell with "2, 4, 7" it would be "2" then next to it "4' then next to it "7"?
byundtMechanical EngineerCommented:
Try array entering a formula like:
=COUNT(FIND(" " & D2 & ","," " &C:C  & ","))

To array enter the formula:
1) Paste the formula in the formula bar
2) Hold Control and Shift keys down
3) Hit Enter
4) Release all three keys. Excel will respond by adding curly braces { } surrounding your formula.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AshokSr. Software EngineerCommented:
Would it be easier if the data was broken up into different cells? So, instead of a cell with "2, 4, 7" it would be "2" then next to it "4' then next to it "7"?

Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

AshokSr. Software EngineerCommented:
If you separate numbers, it will work like this...

see attached file
byundtMechanical EngineerCommented:
With all due respect, the accepted solution is dreadful.

It is not designed to be copied down, and contains mistakes in logic besides:
The second COUNTIF should use G3:J3 instead of G2:J3

If you are going to go to all the trouble of eliminating the extra spaces, then using Data....Text to Columns to split the data into separate cells, you ought to take advantage of the full capability of COUNTIF function to look at multiple columns. COUNTIF can even check columns to the right of the range with the limited set of sample data.

I've posted a sample workbook showing how the suggested array formula works with the data in the original question, as well as the revised COUNTIF formula.

AshokSr. Software EngineerCommented:
The formula is not desined to copy down.  That is correct.



The second COUNTIF should use G3:J3 instead of G2:J3.   Thanks for point it out.
byundtMechanical EngineerCommented:
According to the original question <<Column C has long list of data>>. The Accepted Solution, however, uses one COUNTIF for each row of data in column C. With only seven rows of data in column C of the test workbook, I admit that one can write a brute force formula using seven COUNTIF functions. But the lack of $ dollar signs on the search range means you can't copy the formula down, letting the reference to cell D2 update, but keeping the row references fixed for columns G through K.

Furthermore, the Accepted Solution doesn't scale. If you have hundreds of rows of data the formula gets so long that you can't find a typo if one exists. Worse yet, you eventually reach the maximum allowable number of characters in an Excel formula--255 in Excel 2003 and 8192 in Excel 2010.

The above issues are why I was left spluttering when the question was closed.

I agree that splitting the data the way you have done offers some significant benefits. I also agree that COUNTIF is the right type of formula to use on the data once it is split. Where we differ is how to set up that COUNTIF.

AshokSr. Software EngineerCommented:

Here is real solution that could be easily copy and pasted with CountIF().

Create a Named Range called "Test1" by selecting G2:J8 (all cells) and naming it "Test1", then

Use following in Row # 2.....


and copy and paste above in all following rows (from Row # 3 to Row # 12)

byundtMechanical EngineerCommented:
I agree 100% with the direction of your latest suggestion.

AshokSr. Software EngineerCommented:
http:#a37807775 is a functional solution (what I mean is that it works) except that it had 1 character mistyped,

byundtMechanical EngineerCommented:
With all due respect, http:#a37807775 is a valid solution only for the sample workbook posted by cansevin. It cannot possibly be used for the real problem of picking winning lottery numbers given a column C full of numbers chosen in previous draws (or whatever it is that cansevin is doing).

Your suggestion in http:#a37809216 is a much more general solution to the problem. Absent more pertinent feedback from cansevin, I believe it will work perfectly in the Asker's real workbook. If this question is referred to by another person needing help, '216 is the Comment you want to suggest he follow. And I'd be completely OK with making that Comment the Answer to this Question.

AshokSr. Software EngineerCommented:

I downloaded your excel file from http:#a37808405 and looked at it.

The revised formulas look good to me.
For example


In above, you removed the row # (and it does not require multiple CountIf(s)) which makes it possible to copy & paste it.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.