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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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

SourceResult
Pearl HarborPH
What will be it will beWWBIW
Hello worldHW
To be or not to BeTBONT
Alpha and OmegaAAO
Mark John Susan Dimitr Andrew Oracle IBM DynastyMJSDA
SSDS
The Greatest Show On EarthTGSOE

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
You're quite welcome, happy to help.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,865
Members
449,052
Latest member
Fuddy_Duddy

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