how to count number of text entries in a range?

Lyle Blosser

New Member
Joined
Feb 5, 2010
Messages
3
I have a spreadsheet with a named range ("Names") that contains a list of business names. I want to find out how many businesses have names starting with the letters specified in an interval. For example, I want to answer a question like:

How many businesses have names that start with letters from A-C?
How many businesses have names that start with AM-AT?
etc.

What is the best way to do this? I tried playing around with COUNTIF, but the only way I could come up with an answer was to combine multiple COUNTIF functions. For example, to look for names that start with A-C, I had to write =COUNTIF(Names,"A*")+COUNTIF(Names,"B*")+COUNTIF(Names,"C*"). This is OK for a short range, but gets unwieldy for longer ranges. For example, if I wanted to look for A-M, I would need 13 terms.

I would also like to be able to specify the begining and end of the range in separate cells (ex: A1="AM", B1="AT") and have the formula use those cells.

Any ideas?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi Lyle,

Welcome to MrExcel.

This may not be the best solution or the one you want, but it may help point you in the right direction. This is a snap shot of 2800+ rows of data (NYSE)...


Excel Workbook
ABC
1NameCriteriaCount
2A. Schulman, Inc.A258
3A.C. Moore Arts & Crafts, Inc.B120
4A123 Systems, Inc.C324
5AAON, Inc.D84
6Aastrom Biosciences, Inc.E114
7ABAXIS, Inc.F123
8Abington Bancorp, Inc.G95
9ABIOMED, Inc.H95
10Abraxas Petroleum CorporationI142
11Acacia Research CorporationJ30
12ACADIA Pharmaceuticals Inc.K42
13Accelrys, Inc.L92
14Access National CorporationM155
Sheet2


The formula in C2 needs to be copied all the way down your criteria range.

Have a look at the file here....

Lyle.xls

The formula is counting the first letter of each name in the list that matches A, B, C etc. You can change the 1 after Names, and the criteria B2 to something else like =SUMPRODUCT(--(LEFT(Names,2)=D2)) D2 being another criteria, something like this....

Excel Workbook
DE
1CriteriaCount
2AB4
3AC19
4AD13
5AE6
6AF4
7AG3
8AH0
9AI5
Sheet2



I hope that helps.

Good luck

Ak
 
Upvote 0
Thanks for that prompt reply! I had not considered SUMPRODUCT, and your solution has definite possibilities. The only downside I see is that I would have to specify individually all of the items within each desired interval -- I am still hoping to discover how to simply specify the beginning and end of the interval. But, in the meantime, I will look at your solution in detail -- and, as you suggested, this may help point me in the direction I need to go. Thanks again.
 
Upvote 0
Sweet! That provided the hint I needed to get my solution in place. My final formula is something like this:

=COUNTIF(Names,">=" & A4)-COUNTIF(Names,">" & B4 & "Z")

Cell A4 contains the beginning of the interval and cell B4 contains the ending of the interval. In order to make sure I pick up all of the cells that begin with the ending cell text, I append the character "Z" as shown.

Thanks for that elegant technique!
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

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