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:

Austria
Belgium
Bulgaria
Croatia
Cyprus
Czech Republic
Denmark
Estonia
Finland
France
Germany
Greece
Hungary
Ireland
Italy
Latvia
Lithuania
Luxembourg
Malta
Netherlands
Poland
Portugal
Romania
Slovakia
Slovenia
Spain
Sweden
United Kingdom

<colgroup><col></colgroup><tbody>
</tbody>
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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