Thank you for this formula. The names I have listed are separated by
spaces , yes.
I did apply the formula , and it gave #VALUE! Errors for the target
names containing two elements. It's just names with two elements
separated with a comma that I need to invert.
Other entries with one , three or more elements were treated correctly
by the formula , and left with no change.
Either you made a typo when you copied my formula, or your newsreader
added some additional characters or spaces, or your names are not
entered in the ways you have described.
Between your first post, and this one, you have described multiple
ways in which the first name and last name might be separated:
====================================
Surname , Christian Name
<LastName><space><comma><space><FirstName>
-------------------------------------
Smith John
<LastName><space><FirstName>
---------------------------------------
The names I have listed are separated by
spaces
--------------------------------------
It's just names with two elements
separated with a comma that I need to invert.
==============================
The only one of those formats that my formula will not handle, is the
last, where you write that the names are separated only by a comma (no
spaces), but, in that case, it will not give a VALUE error; it will
only return the string unchanged.
Please copy and paste (don't type) the cell entry that results in the
VALUE error; and also copy and paste the formula as you have it on
your worksheet for that cell.
Or the following User Defined Function should handle all of those
different varieties:
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
=RevLastFirst(A1)
in some cell.
======================================
Option Explicit
Function RevLastFirst(s As String) As String
Dim re As Object, mc As Object
Const sPat As String = "^(\b\S+\b)[^-\w]+(\b\S+\b)$"
Dim sTrimmed As String
sTrimmed = Trim(s)
Set re = CreateObject("vbscript.regexp")
re.Pattern = sPat
re.Global = True
RevLastFirst = re.Replace(sTrimmed, "$2 $1")
End Function
==========================- Hide quoted text -
- Show quoted text -