How to do I change last name to last intial

Ivn68

Board Regular
Joined
Aug 21, 2015
Messages
82
Inside a cell I have First name, Last name
I want to use a vba to convert a it to First name, and Last initial for a whole list of names
 
If the answer to my above question is "Yes", this should do that:
VBA Code:
Sub FixNames2()

    Dim lr As Long
    Dim cell As Range
    Dim x As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through each cell in selection
    For Each cell In Range("A2:A" & lr)
'       Locate comma and space
        x = InStr(cell, ", ")
'       If found, fix name
        If x > 0 Then cell.Value = Trim(Mid(cell, x + 1)) + ", " + Left(cell, 1)
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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