ACRONYM

Returns the first letter of each word.
For instructions on how to add a function to a workbook refer to the page under Inserting Functions


microsoft excel docs

Remarks

* The equivalent JavaScript function is ACRONYM


sText - The text you want the acronym for. 
bJustCapitals - (Optional) Whether to just use the words that start with a capital letter.

Public Function ACRONYM(ByVal sText As String, _
               Optional ByVal bJustCapitals As Boolean = False) As String

Dim inextspace As Integer
Dim sfirstcharacter As String
Dim sword As String

    sText = VBA.Trim(sText)
    Do While VBA.Len(sText) > 0
       inextspace = VBA.InStr(1, sText, " ")
       If inextspace > 0 Then
          sword = VBA.Trim(VBA.Left(sText, inextspace - 1))
          sText = VBA.Right(sText, VBA.Len(sText) - inextspace)
       Else
          sword = sText
          sText = ""
       End If
       
       sfirstcharacter = VBA.Left(sword, 1)
       If bJustCapitals = True Then
          If (VBA.Asc(sfirstcharacter) >= 65 And VBA.Asc(sfirstcharacter) <= 90) Then
             ACRONYM = ACRONYM & VBA.UCase(sfirstcharacter)
          End If
       End If
       
       If bJustCapitals = False Then ACRONYM = ACRONYM & VBA.UCase(sfirstcharacter)
    Loop
End Function

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext