get the first letter of each word in a string

LFKim2018

Active Member
Joined
Mar 24, 2018
Messages
267
say, I have a string: "The Greatest Show On Earth"
I just want to have the first letters of each word: "TGSOE"
pls help with the formula (not VBA) - maximum words per string = 5
many many thanks
 
Mr. jtakw

one more favor - what if I want to limit the letters to just the first 2 or 3
how would I adjust your formula?
many many thanks
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
what if I want to limit the letters to just the first 2 or 3
For my formula for

1 letter use red
2 letters use red & blue
3 letters use red, blue & green
etc
=LEFT(A1,1)&MID(A1,FIND("#",SUBSTITUTE(A1&REPT(" ",4)," ","#",1))+1,1)&MID(A1,FIND("#",SUBSTITUTE(A1&REPT(" ",4)," ","#",2))+1,1)&MID(A1,FIND("#",SUBSTITUTE(A1&REPT(" ",4)," ","#",3))+1,1)&MID(A1,FIND("#",SUBSTITUTE(A1&REPT(" ",4)," ","#",4))+1,1)
 
Last edited:
Upvote 0
You could also simply adjust the function provided by changing the numbers in red to whatever you need

Code:
Function GFL(rng As Range) As String
    Dim arr
    Dim I As Long
    arr = VBA.Split(rng, " ")
    If IsArray(arr) Then
        For I = LBound(arr) To UBound(arr)
            GFL = GFL & Left(arr(I), [color=red]1[/color])
        Next I
    Else
        GFL = Left(arr, [color=red]1[/color])
    End If
End Function
 
Upvote 0
what if I want to limit the letters to just the first 2 or 3
how would I adjust your formula?
many many thanks

I'm not entirely sure what you mean...
We can reduce (cut parts, use only parts of) my formula like PeterSSs suggestion above, or do you mean you want the formula to be User assignable for Number of Characters to extract?

If it's the latter, you can do this:

C1 formula references D1 (User Input) to decide how many characters to extract, enter any number between 1 to 5, if left blank, will return the first character only.


Book1
ABCD
1The Greatest Show On EarthTGSOETG2
2Just Another SampleJASJA
Sheet255
Cell Formulas
RangeFormula
B1=LEFT(A1,1)&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),100,100)),1)&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),200,100)),1)&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),300,100)),1)&LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),400,100)),1)
C1=LEFT(A1,1)&IF(D$1>=2,LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),100,100)),1),"")&IF(D$1>=3,LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),200,100)),1),"")&IF(D$1>=4,LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),300,100)),1),"")&IF(D$1>=5,LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),400,100)),1),"")
 
Last edited:
Upvote 0
Another option, you can try with PowerQuery aka Get&Transform

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]Source[/td][td][/td][td=bgcolor:#70AD47]Result[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Pearl Harbor[/td][td][/td][td=bgcolor:#E2EFDA]PH[/td][/tr]

[tr=bgcolor:#FFFFFF][td]What will be it will be[/td][td][/td][td]WWBIW[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Hello world[/td][td][/td][td=bgcolor:#E2EFDA]HW[/td][/tr]

[tr=bgcolor:#FFFFFF][td]To be or not to Be[/td][td][/td][td]TBONT[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Alpha and Omega[/td][td][/td][td=bgcolor:#E2EFDA]AAO[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Mark John Susan Dimitr Andrew Oracle IBM Dynasty[/td][td][/td][td]MJSDA[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]SSD[/td][td][/td][td=bgcolor:#E2EFDA]S[/td][/tr]

[tr=bgcolor:#FFFFFF][td]The Greatest Show On Earth[/td][td][/td][td]TGSOE[/td][/tr]
[/table]


Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    SplitResult = Table.SplitColumn(Source, "Source" , Splitter.SplitTextByDelimiter(" "), 5 ),
    #"Extracted First Characters" = Table.TransformColumns(SplitResult, {{"Source.1", each Text.Start(_, 1), type text}, {"Source.2", each Text.Start(_, 1), type text}, {"Source.3", each Text.Start(_, 1), type text}, {"Source.4", each Text.Start(_, 1), type text}, {"Source.5", each Text.Start(_, 1), type text}}),
    #"Merged Columns" = Table.CombineColumns(#"Extracted First Characters",{"Source.1", "Source.2", "Source.3", "Source.4", "Source.5"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Result"),
    #"Uppercased Text" = Table.TransformColumns(#"Merged Columns",{{"Result", Text.Upper, type text}})
in
    #"Uppercased Text"[/SIZE]

Text can be longer than 5 words but PQ cut it just to 5
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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