countif for letters, possible?

Jennifre

Board Regular
Joined
Jan 11, 2011
Messages
160
Hi, I tried this, a formula to count the occurrence of the state abbreviations in a row of them.

I've obviously gone wrong (I get, "The formula you typed contains an error," though I see none. I edited this from a countif for numbers.

If anyone can tell where I have gone wrong, that'd be great; thanks!

My effort:
=COUNTIF(BZ2,{"CA","AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN";16,"IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY"})
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi, I tried this, a formula to count the occurrence of the state abbreviations in a row of them.

I've obviously gone wrong (I get, "The formula you typed contains an error," though I see none. I edited this from a countif for numbers.

If anyone can tell where I have gone wrong, that'd be great; thanks!

My effort:
=COUNTIF(BZ2,{"CA","AL","AK","AZ","AR","CA",..."IN";...})
There is a semi-colon after "IN" where there should be a comma.

However, that formula will only look for the first criteria "CA" which you have listed twice. All the other criteria are ignored.

Why don't you use a range of cells to hold the 50 state abbreviations and then refer to that range?

A2:A51 = state abbreviations

Then:

=COUNTIF(A2:A51,BZ2)
 
Last edited:
Upvote 0
Hm, thank you so much for that! However, when I tried it, the counts are not accurate, and they go beyond the number of state abbreviations I have referenced.

Thank you... I'm so, so dorky in Excel. Thanks so much.

Outline: I have your recommended column of state abbreviations in a column referred to by the formula cell, though in spite of there being only 52 rows / state abbreviations, the last number repeats to eternity, if I pull it that long. Usually this type of formula is repeating 0s once there is no additional data options to "countif".

Is there a mistake made given this repeat of the last countif'd data ?

Thanks again. :)
 
Upvote 0
no the pretties responce but I have given the bright people to sort it so here come the "thickies"

assuming state abbreviations are in A3:A55

and you type CA in A1

in B3 use this formula

=IF($A$1=A3,1,"") and drag along then in B2

=SUM(C3:C55)

If you have "stuff" in row 2 use row 100 or 1000
 
Upvote 0
Hi, I tried this, a formula to count the occurrence of the state abbreviations in a row of them.

I've obviously gone wrong (I get, "The formula you typed contains an error," though I see none. I edited this from a countif for numbers.

If anyone can tell where I have gone wrong, that'd be great; thanks!

My effort:
=COUNTIF(BZ2,{"CA","AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN";16,"IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY"})
Hello,

Perhaps this could help you.

Below is the data on BZ2

<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>BZ</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">2</td><td style=";">CA AK AL PP AA SS 16 GA ID</td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Sheet2</p><br /><br />

This formula will give you count 6

Code:
=SUM(COUNTIF(BZ2,"*"&{"CA";"AL";"AK";"AZ";"AR";"CO";"CT";"DE";"DC";"FL";"GA";"HI";"ID";"IL";"IN";16;"IA";"KS";"KY";"LA";"ME";"MD";"MA";"MI";"MN";"MS";"MO";"MT";"NE";"NV";"NH";"NJ";"NM";"NY";"NC";"ND";"OH";"OK";"OR";"PA";"RI";"SC";"SD";"TN";"TX";"UT";"VT";"VA";"WA";"WV";"WI";"WY"}&"*"))
 
Upvote 0
If you do have a list of state abbreviations in a range make sure that part of the formula is an absolute reference.

If it isn't and you drag the formula the reference will change, and probably be incorrect.
 
Upvote 0

Forum statistics

Threads
1,224,538
Messages
6,179,412
Members
452,912
Latest member
alicemil

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