Macro to take only initials of a person

kupseker

New Member
Joined
Feb 1, 2016
Messages
13
Hey there,

I need a macro that takes only initials of a person;

For example : In A1 cell: Keanu Reeves -----Macro-----> In A2 cell: KR

Thanks in advance!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If you always have a First Name and last name with a single space between them, this will work:
Code:
=LEFT(A1,1) & MID(A1,FIND(" ",A1)+1,1)
 
Upvote 0
The person can have middle name as well bu not necessarily, therefore I need something more flexible and applicable but thanks for a starter.
 
Upvote 0
OK. It is always best to lay out all your conditions/possibilities up front. In this situation, since there are an unknown number of initials, I would probably elect to create my own function to it in VBA, like this:
Code:
Function GetInitials(myName As String) As String

    Dim myLen As Long
    Dim i As Long
    Dim myInit As String

    myLen = Len(myName)

'   Exit function if zero length string
    If myLen = 0 Then Exit Function
    
'   Get first letter
    myInit = Left(myName, 1)
    
'   Loop through name
    If myLen > 2 Then
        For i = 2 To myLen - 1
            If Mid(myName, i, 1) = " " Then
                myInit = myInit & Mid(myName, i + 1, 1)
            End If
        Next i
    End If
    
'   Return value
    GetInitials = myInit
    
End Function
So, then we would just use this like any other function:
=GetInitials(A1)
 
Upvote 0

Forum statistics

Threads
1,223,919
Messages
6,175,371
Members
452,638
Latest member
Oluwabukunmi

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