Create Acronyms From Strings of Text
The following function evaluates Acronyms from strings i.e it concatenates the first letter in every word in a string. E.g “trees are green” becomes “TAG”.
The routine traverses every character in a string and if it is a space then it takes the next character in the string. Before evaluating the string, it removes all trailing and duplicate spaces.
Function Acroymn (Original_String As String) As String Dim Trimmed_String As String Dim Length As Integer Dim Pos As Integer Trimmed_String = Application.WorksheetFunction.Trim(Original_String) 'work out the length of the string Length = Len(Trimmed_String) Acroymn = UCase(Left(Trimmed_String, 1)) For Pos = 2 To Length - 1 If (Mid(Trimmed_String, Pos, 1) = " ") Then Acroymn = Acroymn & UCase(Mid(Trimmed_String, Pos + 1, 1)) End If Next Pos End Function
So for example :
Acroymn (“British Broadcasting Corporation”) gives BBC
Acroymn (“Funky”) gives F
Acroymn (“”) gives NULL
VBA Coding Made Easy
Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!