vba.split function with multiple delimeters

Smurphster16

New Member
Joined
Feb 28, 2019
Messages
24
Hi,

I currently have the following code where when the function is used in excel it retrieves the first letter of each word within the cell when the words are separated by spaces.

I want to edit the function so the first letter of the words are also retrieved if they are seperated by a forward slash or a dash as well as a space - but not sure if the VBA split function allows for multiple delimeters?

e.g Currently if i apply the function to the cell containing Equity Long/short it returns EL but I would like it to return ELS

Thanks so much for any help!

Code:
Function getfirstletters(rng As Range) As StringDim I As Long


arr = VBA.Split(rng, " ")


    If IsArray(arr) Then
    For I = LBound(arr) To UBound(arr)
        getfirstletters = getfirstletters & Left(arr(I), 1)
        Next I
        
    Else
        getfirstletters = Left(arr, 1)
        
    End If
  


End Function
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I rewrote that a little bit, but you don't really need to check for multiple delimiters, just change those characters in the code to a space and do a regular Split.

Code:
Function GetFirstLetters(r As Range) As String
Dim t As Long, arr
arr = Split(Replace(Replace(r, "/", " "), "-", " "))
For t = 0 To UBound(arr)
    arr(t) = UCase(Left(arr(t), 1))
Next
GetFirstLetters = Join(arr, "")
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,082
Messages
6,053,419
Members
444,662
Latest member
AaronPMH

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