Extract first 3 Characters from each word

jarett

Board Regular
Joined
Apr 12, 2021
Messages
165
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Trying to extract the first three characters from each word in a cell, I was reading this article to extract the first character. Not sure if I could use this with some revision to get what I need. This is what I am trying to do
Cell A1 = Electric Blue/ Electric Blue Tonal Blend
Desired output = Ele Blu Ele Blu Ton Ble
I am indifferent on the "/" being left in and I would rather do away with the spaces in the output.
How to extract first letter of each word from cell?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about this?

Book3 (version 2).xlsb
AB
1Electric Blue/ Electric Blue Tonal BlendEle Blu Ele Blu Ton Ble
Sheet6
Cell Formulas
RangeFormula
B1B1=TEXTJOIN(" ",1,LEFT(FILTERXML("<a><b>" & SUBSTITUTE(A1," ","</b><b>") & "</b></a>","//b"),3))
 
Upvote 0
How about
Fluff.xlsm
AB
1
2Electric Blue/Electric Blue Tonal BlendEle Blu Ele Blu Ton Ble
Test
Cell Formulas
RangeFormula
B2B2=TEXTJOIN(" ",,LEFT(FILTERXML("<k><m>"&SUBSTITUTE(SUBSTITUTE(A2,"/"," ")," ","</m><m>")&"</m></k>","//m"),3))
 
Upvote 0
If you like using the UDF, try this modification:
VBA Code:
Function GetFirstLetters(rng As Range) As String
'Update 20140325
    Dim arr
    Dim I As Long
    arr = VBA.Split(rng, " ")
    If IsArray(arr) Then
        For I = LBound(arr) To UBound(arr)
            GetFirstLetters = GetFirstLetters & Left(arr(I), 3) & " "
        Next I
    Else
        GetFirstLetters = Left(arr, 3) & " "
    End If
    
    GetFirstLetters = Trim(GetFirstLetters)
    
End Function
 
Upvote 0
Solution
If you like using the UDF, try this modification:
VBA Code:
Function GetFirstLetters(rng As Range) As String
'Update 20140325
    Dim arr
    Dim I As Long
    arr = VBA.Split(rng, " ")
    If IsArray(arr) Then
        For I = LBound(arr) To UBound(arr)
            GetFirstLetters = GetFirstLetters & Left(arr(I), 3) & " "
        Next I
    Else
        GetFirstLetters = Left(arr, 3) & " "
    End If
   
    GetFirstLetters = Trim(GetFirstLetters)
   
End Function
This one worked great, thanks.
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,742
Members
448,989
Latest member
mariah3

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