How to count acronyms is text (i.e., number of times between 2 and 5 capital letters appear as consecutive characters)

ea2146

New Member
Joined
Apr 9, 2012
Messages
30
Hello,

Thank you in advance for any suggestions! I have a corpus of written comments and would like to identify the number of acronyms that appear in each cell of text. Of course, there is no perfect way to do this, but one idea I had is to create an excel function that counts the number of times between 2 and 5 capital letters appear as consecutive characters. I chose 5 as the high end of the range because very few acronyms are more than 5 letters long and a function that indiscriminately identifies consecutive capital letters would incorrectly identify text that is written in all caps as an acronym.

Below is an illustration of what I need. I have the sentences in the "TEXT" column and would like a function that produces the values in the other column.

Any ideas would be greatly appreciated!! Thank you so much for taking the time to help! :)


TEXTNUMBER OF ACRONYMS
This sentence has no acronyms0
I launched a word-of-mouth marketing (WOMM) campaign.1
I have experience in BTC and BTB2
This sentence has no acronyms0
Neither does this one.0
He worked at a PR agency1
THIS SENTENCE IS ALL CAPS0
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Here's a UDF that should do that:

VBA Code:
Function COUNTACRO(r As String) As Long
With CreateObject("vbscript.regexp")
    .Pattern = "[A-Z]{2,5}"
    .Global = True
    If .test(r) And r <> UCase(r) Then COUNTACRO = .Execute(r).Count
End With
End Function

Book1
AB
1TEXTNUMBER OF ACRONYMS
2This sentence has no acronyms0
3I launched a word-of-mouth marketing (WOMM) campaign.1
4I have experience in BTC and BTB2
5This sentence has no acronyms0
6Neither does this one.0
7He worked at a PR agency1
8THIS SENTENCE IS ALL CAPS0
Sheet1
Cell Formulas
RangeFormula
B2:B8B2=countacro(A2)
 
Upvote 0
Here's a UDF that should do that:

VBA Code:
Function COUNTACRO(r As String) As Long
With CreateObject("vbscript.regexp")
    .Pattern = "[A-Z]{2,5}"
    .Global = True
    If .test(r) And r <> UCase(r) Then COUNTACRO = .Execute(r).Count
End With
End Function

Book1
AB
1TEXTNUMBER OF ACRONYMS
2This sentence has no acronyms0
3I launched a word-of-mouth marketing (WOMM) campaign.1
4I have experience in BTC and BTB2
5This sentence has no acronyms0
6Neither does this one.0
7He worked at a PR agency1
8THIS SENTENCE IS ALL CAPS0
Sheet1
Cell Formulas
RangeFormula
B2:B8B2=countacro(A2)
This is great, can you kindly explain the logic behind this code? I have never seen CreateObject("vbscript.regexp") before.
 
Upvote 0
This works perfectly!! I can't thank you enough. Much appreciated! I also appreciate the discussion of the inner workings for the UDF.
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

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