View Single Post
 
Old 01-14-2019, 08:54 AM
0rion 0rion is offline Windows 10 Office 2010
Novice
 
Join Date: Jan 2019
Posts: 11
0rion is on a distinguished road
Default Adjust Acronym Script to include Dashes?

Hi,

I have data that contains dashes that I would like to abbreviate by just having the first letter of each word. I found several VBA Acronym scripts that work, but they look at the spaces so the words after the dashes get lost.

example: Projects-North America-Canada-Alberta-Moose Jaw

would yield: PAJ

I found a script that works much better:
Code:
Function Acronym(str As String) As String
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "(\w).*?(\W+|\s+|$)"
Acronym = UCase(re.Replace(str, "$1"))
End Function
Yields: PNACAMJ

Is there a way to modify this script to retain the dashes?

Desired: P-NA-C-A-MJ

Thanks.
Reply With Quote