Find text characters in cell and add to end

Hawk04

New Member
Joined
Apr 1, 2010
Messages
8
Hi: I'm trying to figure out a method in VBA code to find the initials in a text string (name) and add them to the end of the string in the same cell. The format is:

Doe, John

I want to find the J first, D second and add them to the end of the name to show as:

Doe, John (JD)

I have the code written to find the cell with the correct name, but have not figured out the remainder. Here is what I have so far:

Code:
    Worksheets("Reg_Scores").Activate
    For PlayerRow = 1 To 50
        Set PlayerCell = Range("B3").Offset(PlayerRow - 1, 0)
        PlayerCell.Select
        If PlayerCell.Text = cmbPlayer.Text Then
            PlayerCell.Activate
            ActiveCell.EntireRow.Copy
            Worksheets("Sub_Scores").Activate
            Range("B3").End(xlDown).Select
            Selection.EntireRow.Insert Shift:=xlDown 'Is it possible to auto populate initials after name, format " (1stlast)"?
            Selection.Offset(0, -1).ClearContents
            Selection.Offset(0, -1).ClearFormats
        Exit For
    End If
    Next PlayerRow

Thanks in advance for any help...
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi and welcome. Try something like this...

Code:
    Dim PlayerCell As Range, Dest As Range
    
    Set Dest = Worksheets("Sub_Scores").Range("B3").End(xlDown)
    
    For Each PlayerCell In Worksheets("Reg_Scores").Range("B3:B53")
        
        If PlayerCell.Text = cmbPlayer.Text Then
            PlayerCell.EntireRow.Copy Destination:=Dest.EntireRow
            Dest = PlayerCell.Value & " (" & Mid(PlayerCell, InStr(1, PlayerCell, ", ", 1) + 2, 1) & Left(PlayerCell, 1) & ")"
            Dest.Offset(0, -1).ClearContents
            Dest.Offset(0, -1).ClearFormats
            Exit For
        End If
        
    Next PlayerCell
 
Upvote 0

Forum statistics

Threads
1,224,588
Messages
6,179,743
Members
452,940
Latest member
rootytrip

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