Counting number of text strings in a cell

lyman

New Member
Joined
Aug 23, 2013
Messages
19
Hello

I would like to write a formula that would give me the number of EU countries listed in a single cell. So for instance if I was to check the below cell the result of the formula would be 3.

CELL A1: Australia,China,Germany,France,South Africa,Spain

There are 28 EU countries so I was thinking to nest the If function 28 times (each EU country spelt out) with ISNUMBER and SEARCH function. However I don't know how to then count the number of times there would be a match in the cell.

Much appreciate suggestions. Maybe there is an easy way of doing this and I'm thinking completely wrong about it.

Thanks
 
Sorry typo my typo, I should have written 28 above, as you found. However the formula in my spreadsheet is finding 5 only. I'm sure i adapted as necessary.
{=SUM(--ISNUMBER(SEARCH($F$1:$F$28,A1)))}

The list (F1:F28) I use is:

[TABLE="width: 108"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Austria [/TD]
[/TR]
[TR]
[TD]Belgium [/TD]
[/TR]
[TR]
[TD]Bulgaria [/TD]
[/TR]
[TR]
[TD]Croatia [/TD]
[/TR]
[TR]
[TD]Cyprus [/TD]
[/TR]
[TR]
[TD]Czech Republic [/TD]
[/TR]
[TR]
[TD]Denmark [/TD]
[/TR]
[TR]
[TD]Estonia [/TD]
[/TR]
[TR]
[TD]Finland[/TD]
[/TR]
[TR]
[TD]France [/TD]
[/TR]
[TR]
[TD]Germany [/TD]
[/TR]
[TR]
[TD]Greece [/TD]
[/TR]
[TR]
[TD]Hungary [/TD]
[/TR]
[TR]
[TD]Ireland [/TD]
[/TR]
[TR]
[TD]Italy [/TD]
[/TR]
[TR]
[TD]Latvia [/TD]
[/TR]
[TR]
[TD]Lithuania [/TD]
[/TR]
[TR]
[TD]Luxembourg [/TD]
[/TR]
[TR]
[TD]Malta [/TD]
[/TR]
[TR]
[TD]Netherlands [/TD]
[/TR]
[TR]
[TD]Poland [/TD]
[/TR]
[TR]
[TD]Portugal [/TD]
[/TR]
[TR]
[TD]Romania [/TD]
[/TR]
[TR]
[TD]Slovakia [/TD]
[/TR]
[TR]
[TD]Slovenia [/TD]
[/TR]
[TR]
[TD]Spain [/TD]
[/TR]
[TR]
[TD]Sweden [/TD]
[/TR]
[TR]
[TD]United Kingdom[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Your list is the same as mine and there are all 28 counties in your text string which is what I get with Fluff's formula.


Excel 2010
ABCDEF
1Uganda,Zimbabwe,Zambia,Yemen,Vietnam,Venezuela,Vatican City (Holy See),Vanuatu,Uzbekistan,Uruguay,United States Of America,United States Minor Outlying Islands,United Kingdom,United Arab Emirates,Afghanistan,Albania,Algeria,Andorra,Angola,Antigua And Barbuda,Argentina,Armenia,Australia,Austria,Azerbaijan,Bahamas,Bahrain,Bangladesh,Barbados,Belarus,Belgium,Belize,Benin, Bermuda,Bhutan,Bolivia,Bosnia And Herzegovina,Botswana,Brazil,Brunei,Bulgaria,Burkina Faso,Burundi,Cambodia,Cameroon,Canada,Cape Verde,Central African Republic,Chad,Chile,China,Colombia,Comoros,Costa Rica,Croatia,Cuba,Cyprus,Czech Republic,Democratic Republic Of The Congo,Denmark,Djibouti,Dominica,Dominican Republic,Ecuador,Egypt,El Salvador,Equatorial Guinea,Eritrea,Estonia,Eswatini (Formerly Swaziland),Ethiopia,Fiji,Finland,France,Gabon,Gambia,Georgia,Germany,Ghana,Greece,Grenada,Guatemala,Guinea,Guinea-Bissau,Guyana,Haiti,Honduras,Hong Kong,Hungary,Iceland,India,Indonesia,Iran,Iraq,Ireland,Israel,Italy,Jamaica,Japan,Jordan,Kazakhstan,Kenya,Kiribati,Kosov o,Kuwait,Kyrgyzstan,Laos,Latvia,Lebanon,Lesotho,Liberia,Libya,Liechtenstein,Lithuania,Luxembourg,Macedonia (Fyrom),Madagascar,Malawi,Malaysia,Maldives,Mali,Malta,Marshall Islands,Mauritania,Mauritius,Mexico,Micronesia,Moldova,Monaco,Mongolia,Montenegro,Morocco,Mozambique,Myanmar (Formerly Burma),Namibia,Nauru,Nepal,Netherlands,New Zealand,Nicaragua,Niger,Nigeria,North Korea,Norway,Oman,Pakistan,Palau,Palestine,Panama,Papua New Guinea,Paraguay,Peru,Philippines,Poland,Portugal,Qatar,Republic Of The Congo,Romania,Russia,Rwanda,Saint Kitts And Nevis,Saint Lucia,Saint Vincent And The Grenadines,Samoa,San Marino,Sao Tome And Principe,Saudi Arabia,Senegal,Serbia,Seychelles,Sierra Leone,Singapore,Slovakia,Slovenia,Solomon Islands,Somalia,South Africa,South Korea,South Sudan,Spain,Sri Lanka,Sudan,Suriname,Swaziland,Sweden,Switzerland,Syria,Taiwan,Tajikistan,Tanzania,Thailand,Timor-Leste,Togo,Tonga,Trinidad And Tobago,Tunisia,Turkey,Turkmenistan,Tuvalu,Ukraine28Austria
2Belgium
3Bulgaria
4Croatia
5Cyprus
6Czech Republic
7Denmark
8Estonia
9Finland
10France
11Germany
12Greece
13Hungary
14Ireland
15Italy
16Latvia
17Lithuania
18Luxembourg
19Malta
20Netherlands
21Poland
22Portugal
23Romania
24Slovakia
25Slovenia
26Spain
27Sweden
28United Kingdom
Sheet3
Cell Formulas
RangeFormula
B1{=SUM(--ISNUMBER(SEARCH($F$1:$F$28,A1)))}
Press CTRL+SHIFT+ENTER to enter array formulas.


I'll upload a copy of the workbook if it helps for you to look at.
 
Last edited:
Upvote 0
If you're still having problems, here is a non-array formula that does the same thing
=SUMPRODUCT(--ISNUMBER(SEARCH(F1:F28,A1)))
 
Upvote 0
If you're still having problems, here is a non-array formula that does the same thing
=SUMPRODUCT(--ISNUMBER(SEARCH(F1:F28,A1)))

In my excel workbook I have tried the array formula with SUM and the non array formula with SUMPRODUCT formulas. I have copied formulas straight into my excel workbook to make sure I'm doing exactly what you have done. The formula is not picking up more than 5 EU countries. When I test I see the formula doesn't pick up countries like Austria but picks up Germany France, UK every time. It's weird. Could it have something to do with my settings in excel?

I downloaded Mark's workbook and in that file it works fine. There is no difference between how both files are set up but the results are different. I'm bemused.
 
Upvote 0
Double check that your countries do not have leading/trailing spaces.
Also where did you get the list of countries from? did you copy & paste them from a website?
 
Upvote 0
Double check that your countries do not have leading/trailing spaces.
Also where did you get the list of countries from? did you copy & paste them from a website?

I had initially formatted text with format painter as I thought that the text might be an issue. However now I deleted column and wrote out the countries manually. It works perfectly now. Thanks!!!
 
Upvote 0
Glad it's working & thanks for the feedback
 
Upvote 0
@lyman, if you get the situation again then there are other options to clean up your data without rewriting everything either by VBA or a formula like
=TRIM(CLEAN(SUBSTITUTE(F1,CHAR(160)," ")))
which will take care of most issues.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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