Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: get the first letter of each word in a string
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    Board Regular
    Join Date
    Mar 2018
    Posts
    267
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: get the first letter of each word in a string

    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

  2. #12
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,222
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: get the first letter of each word in a string

    Quote Originally Posted by LFKim2018 View Post
    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
    Place it inside a call to the LEFT function.
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  3. #13
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    40,969
    Post Thanks / Like
    Mentioned
    90 Post(s)
    Tagged
    21 Thread(s)

    Default Re: get the first letter of each word in a string

    Quote Originally Posted by LFKim2018 View Post
    I am using Excel 2013 version..
    OK, so for a formula solution you would have to use my C1 formula or jtakw's.
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

  4. #14
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    40,969
    Post Thanks / Like
    Mentioned
    90 Post(s)
    Tagged
    21 Thread(s)

    Default Re: get the first letter of each word in a string

    Quote Originally Posted by LFKim2018 View Post
    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 by Peter_SSs; Sep 13th, 2018 at 09:23 PM.
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

  5. #15
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,804
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: get the first letter of each word in a string

    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), 1)
            Next I
        Else
            GFL = Left(arr, 1)
        End If
    End Function
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  6. #16
    Board Regular
    Join Date
    Jun 2014
    Location
    Oakland, CA
    Posts
    5,146
    Post Thanks / Like
    Mentioned
    42 Post(s)
    Tagged
    2 Thread(s)

    Default Re: get the first letter of each word in a string

    Quote Originally Posted by LFKim2018 View Post
    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.

    ABCD
    1The Greatest Show On EarthTGSOETG2
    2Just Another SampleJASJA

    Sheet255



    Worksheet Formulas
    CellFormula
    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 by jtakw; Sep 13th, 2018 at 09:39 PM.

  7. #17
    Board Regular sandy666's Avatar
    Join Date
    Oct 2015
    Posts
    2,805
    Post Thanks / Like
    Mentioned
    32 Post(s)
    Tagged
    1 Thread(s)

    Default Re: get the first letter of each word in a string

    Another option, you can try with PowerQuery aka Get&Transform

    Source Result
    Pearl Harbor PH
    What will be it will be WWBIW
    Hello world HW
    To be or not to Be TBONT
    Alpha and Omega AAO
    Mark John Susan Dimitr Andrew Oracle IBM Dynasty MJSDA
    SSD S
    The Greatest Show On Earth TGSOE


    Code:
    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"
    Text can be longer than 5 words but PQ cut it just to 5
    I know you know but I forgot my Crystal Ball and don't know what you know



    In the first post, show the type of machine (PC / Mac) and the Office version you are working on
    impossible things we do on the spot. for miracles you need to wait for a while

  8. #18
    Board Regular
    Join Date
    Mar 2018
    Posts
    267
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: get the first letter of each word in a string

    Mr. Michael M, jtakw, Peter_SSs

    you all have been very helpful.
    thank you very very much..

  9. #19
    Board Regular
    Join Date
    Mar 2018
    Posts
    267
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: get the first letter of each word in a string

    Mr. Rothstein
    nice trick - though the formula would be quite long...
    many thanks

  10. #20
    Board Regular
    Join Date
    Jun 2014
    Location
    Oakland, CA
    Posts
    5,146
    Post Thanks / Like
    Mentioned
    42 Post(s)
    Tagged
    2 Thread(s)

    Default Re: get the first letter of each word in a string

    You're quite welcome, happy to help.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •