Count Values in Cells

philb99

Active Member
Joined
Feb 3, 2014
Messages
385
Office Version
  1. 2010
Platform
  1. Windows
I have a list of countries recorded in Cells from A2 to A1000, some cells have 4 or more countries recorded, and I want to Count certain countries

I have been using this Formula where I have the country that I am looking for entered into Cell C1

=COUNTIF($A$2:$A$100,"*"&C$1&"*")

What it doesn't do is separate those countries with some of the same name like Sudan and South Sudan also North Korea and South Korea

Therefore can any on help with the formula
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Something like this


Excel 2010
ABCD
1Sudan ArgentinaSudan5
2Niger SudanNigeria1
3Sudan South SudanArgentina3
4ArgentinaKorea4
5North Korea
6Sudan Argentina
7Nigeria
8Niger Chad Mali
9North Korea mali
10South Korea, north Korea
Sheet1
Cell Formulas
RangeFormula
D1{=SUM((LEN($A$1:$A$10)-LEN(SUBSTITUTE($A$1:$A$10,C1,"")))/LEN(C1))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
For including those countries which have some prefix like North or South in your result, change your formula to =COUNTIF($A$2:$A$100,"*"&"?"&C$1&"*").
If you just want to see country names without such prefixes, use your original formula and reduce the result of this modified formula from this. You can do the same thing for suffixes.
 
Upvote 0
I have a list of countries recorded in Cells from A2 to A1000, some cells have 4 or more countries recorded, and I want to Count certain countries

I have been using this Formula where I have the country that I am looking for entered into Cell C1

=COUNTIF($A$2:$A$100,"*"&C$1&"*")

What it doesn't do is separate those countries with some of the same name like Sudan and South Sudan also North Korea and South Korea

Therefore can any on help with the formula

See http://www.mrexcel.com/forum/excel-questions/781938-look-up-values-column-return-where-matched.html

where the following formula is used:

=SUMPRODUCT(ISNUMBER(SEARCH(","&C$1&",",","$A$2:$A$100&","))+0)

Caveat. Target strings separate countries with a comma followed by a space.
 
Upvote 0
thank you but you have added 2 different countries together - All of the Sudan's and all of the Koreas
 
Upvote 0
thank you but you have added 2 different countries together - All of the Sudan's and all of the Koreas

I suppose this is addressing my proposal. If it does, in which way? Also, try to put all possible issues with input at once if possible, note piecemeal.

By the way, the formula I meant to post is:

=SUMPRODUCT(ISNUMBER(SEARCH("#"&C$1&"#","#"&SUBSTITUTE($A$2:$A$100,", ","#")&"#"))+0)

See your original thread...
 
Upvote 0
Thanks but this formula does not bring back the correct numbers
 
Upvote 0
I don't know if that is possible. It would of course be extremely simple if you had several columns, and only one country entered per column. However, if you want to see all the data neatly, say on a printout, that would give a messy result such as (alphabetically):

Argentina North Korea South Korea Zimbabwe

This can be solved by creating a print range. Enter the countries in 4 columns outside of that range.
Then, in the print range, enter a formula such as:

=A1&IF(ISBLANK(B1),"",", "&B1&IF(ISBLANK(C1),"",", "&C1)&IF(ISBLANK(D1),"",", "&D1))

Result:

Argentina, North Korea, South Korea, Zimbabwe

There is a pitfall, that if a leading or trailing space is entered in the data columns, you will see it in the result column. Thus, if the data column containing South Korea is actually entered as "South Korea" and a SPACE, the result will be:

Argentina, North Korea, South Korea , Zimbabwe

If you are worried about such possibility, you can prevent it with the use of the TRIM function:

=TRIM(A1)&IF(ISBLANK(B1),"",", "&TRIM(B1)&IF(ISBLANK(C1),"",", "&TRIM(C1))&IF(ISBLANK(D1),"",", "&TRIM(D1)))

I tested this by entering South Korea 3 ways:

SPACE and "South Korea"
"South" TWO SPACES "Korea"
"South Korea" and SPACE

Excel was smart enough to give the right result each time:

Argentina, North Korea, South Korea, Zimbabwe

In the case that your purpose is not printing, but merely to be seen neatly on the screen, then I would suggest putting your data entry range on a separate sheet of the workbook.

Hope this helps.

Robyn
 
Upvote 0
Aladin - my reply was to Momentman - your formula is missing something possible an & but dont know where
 
Upvote 0
Aladin - my reply was to Momentman - your formula is missing something possible an & but dont know where

You should have stayed in your original thread, where I introduced the following formula

=SUMPRODUCT(ISNUMBER(SEARCH("#"&C$1&"#","#"&SUBSTITUTE($A$2:$A$100,", ","#")&"#"))+0)

for counting.
 
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,025
Members
449,060
Latest member
LinusJE

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