Extract letters

Yippy_Kiyey

Board Regular
Joined
Sep 28, 2008
Messages
96
Hello,

Excel Workbook
ABCD
1Company1st2nd3rd
2American ExpressAE
3Best BuyBB
4AmazonA
5March of DimesMOD
Sheet1
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hello, Sorry, I click submit a little too soon. The thing is I need a formula to put on column C & D that will enter the 1st letter of the company's second name on col C and also the 1st letter of the third name on col D.
I can do col B, for the 1st name using the left function.

Thank you

Rey
 
Upvote 0
Put all this in a standard module and run the macro.

Code:
Function GetFirstLetters(r As String) As Object
Dim m As Object, s As String
r = " " & Trim(r)
With CreateObject("vbscript.regexp")
    .Pattern = " [A-Z]"
    .Global = True
    If .test(r) Then Set m = .Execute(r)
End With
Set GetFirstLetters = m
End Function
 
Sub SplitLetters()
Dim c As Range, t As Object, d, x As Long
For Each c In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    Set t = GetFirstLetters(c.Text)
    If t.Count Then
        For Each d In t
            x = x + 1
            c.Offset(, x) = Trim(d)
        Next
    End If
    x = 0
Next
End Sub
 
Last edited:
Upvote 0
Put this formula in C2....

=UPPER(MID(A2,FIND(" ",A2&" ")+1,1))

and this formula in D2...

=UPPER(MID(A2,FIND(" ",A2&" ",FIND(" ",A2&" ")+1)+1,1))

and copy down as needed.
 
Upvote 0
Formula approach (bit messy):
B2: =LEFT(A2)
C2: =IF(LEN($A2)-LEN(SUBSTITUTE($A2," ",""))>=LEFT(C$1)-1,MID($A2,FIND(" ",$A2)+1,1),"")
D2: =IF(LEN($A2)-LEN(SUBSTITUTE($A2," ",""))>=LEFT(D$1)-1,MID($A2,FIND(" ",$A2,FIND(" ",$A2)+1)+1,1),"")
 
Upvote 0
Thank you for the reply. Does it mean that it can not be done thru a cell formula?
Try this...

Book1
ABCD
1Company1st2nd3rd
2American ExpressAE_
3Best BuyBB_
4AmazonA__
5March of DimesMoD
Sheet1

This formula entered in B2:

=LEFT(TRIM(MID(SUBSTITUTE(" "&$A2&" "," ",REPT(" ",255)),COLUMNS($B2:B2)*255,255)))

Copy down to B5 then across as needed (until you get a full column of blanks).
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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