Hi all -
Non-programmer JTrain went looking for a way to transform a phrase to an acronym in Excel, and thinking strongly of his Google-fu, found this:
Which seemed to do the trick. And there was much rejoicing.
However, there appears to be an issue where if the phrase starts with a number (e.g. "2015 Has Been Awesome") then it ignores the first word following the number. So instead of the above example becoming "HBA" it comes out "BA" instead.
Any ideas of what to change in the above code to correct that?
Thanks!
JT
Non-programmer JTrain went looking for a way to transform a phrase to an acronym in Excel, and thinking strongly of his Google-fu, found this:
Code:
Function Acronym(phrase As String) As String
Dim i As Integer
Dim ch As String, words As String
Acronym = ""
phrase = Trim(phrase)
If Len(phrase) < 1 Then End
words = ""
For i = 1 To Len(phrase)
ch = UCase(Mid(phrase, i, 1))
If ch = "-" Or ch = "/" Then ch = " "
If InStr(" ABCDEFGHIJKLMNOPQRSTUVWXYZ", ch) > 0 Then
words = words & ch
End If
Next i
If (Len(words) < 1) Then End
Acronym = Left(words, 1)
For i = 2 To Len(words)
ch = Mid(words, i, 1)
If ch = " " Then
Acronym = Acronym & Mid(words, i + 1, 1)
End If
Next i
End Function
However, there appears to be an issue where if the phrase starts with a number (e.g. "2015 Has Been Awesome") then it ignores the first word following the number. So instead of the above example becoming "HBA" it comes out "BA" instead.
Any ideas of what to change in the above code to correct that?
Thanks!
JT