On Sun, 8 Nov 2009 15:04:01 -0800, G. B. Needs Excel Help <G. B. Needs Excel
I am looking for an Excel if..then statement to evaluate a name and insert a
period after a single letter if the name contains a single letter. Example
John Q Smith.
Can excel do this for a list of names that are not the same length. Please
help. These are more examples.
John T James
Janice S Smith
Lola P Simpson
You can do this with a User Defined Function.
This function adds a dot "." after any single letter within your string. So,
for example, it will handle names like H J Smith, J Smith.
To enter this User Defined Function (UDF), <alt-F11> opens the Visual Basic
Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.
To use this User Defined Function (UDF), enter a formula like
=ReDot(A1)
in some cell.
=====================================
Option Explicit
Function ReDot(s As String)
Dim re As Object
Set re = CreateObject("vbscript.regexp")
With re
.IgnoreCase = True
.Global = True
.Pattern = "\b([A-Z])(\s|$)"
ReDot = .Replace(s, "$1. ")
End With
End Function
=========================
--ron