Macro to insert a period for single characters in a string

A

Aposto

I want a macro to insert a peroid after any single alpha character in a list
of names in a column. I have a list of names but single alpha characters such
as middle initials don't have a period after it. Can this be done?
 
J

Jacob Skaria

With your names in ColA; try the below macro

Sub Macro()
lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For lngRow = 1 To lngLastRow
arrData = Split(Range("A" & lngRow), " ")
For intTemp = 0 To UBound(arrData)
If Len(arrData(intTemp)) = 1 Then
arrData(intTemp) = arrData(intTemp) & "."
End If
Next
Range("A" & lngRow) = Join(arrData, " ")
Next
End Sub

If this post helps click Yes
 
A

Aposto

Thanks works like a charm!

Jacob Skaria said:
With your names in ColA; try the below macro

Sub Macro()
lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For lngRow = 1 To lngLastRow
arrData = Split(Range("A" & lngRow), " ")
For intTemp = 0 To UBound(arrData)
If Len(arrData(intTemp)) = 1 Then
arrData(intTemp) = arrData(intTemp) & "."
End If
Next
Range("A" & lngRow) = Join(arrData, " ")
Next
End Sub

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top