the macro or vb don't understand because the first name doesn't work out
with the trim function so we want to use the macro
What happened when you followed the instructions in my post???
I have repeated it below. Go through this paragraph by paragraph (starting with
paragraph 4 where I wrote <alt-F11>) and tell me exactly what you did and what
the result was.
=============================================
If I understand you correctly (and you can check by looking at the comments at
the top of this VBA macro), then this should do what you want.
It could be done with formulas, but it would be exceedingly complex and time
consuming to devise.
The Macro could possibly be simplified, but I believe this solution will work.
To enter the Macro, <alt-F11> opens the VBEditor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and paste the
code below into the window that opens.
To use this Macro, select your range of cells. <alt-F8> opens the Macro dialog
box. Select the Macro, and <run>.
Let me know if this does what you need.
===================================================
Option Explicit
Sub SplitSpecial()
'splits multi-word string into adjacent
' columns as follows
'1 word --> col2
'2 words --> col1 & col2
'3 words --> 1st 2 in col1; last in col2
'4+ words --> 1st in col1; last in col3; rest in col2
Dim c As Range
Dim re As Object, mc As Object, m As Object
Dim i As Long
Set re = CreateObject("vbscript.regexp")
re.Pattern = "^(\w+\b)?(\s*(.*?)\s*)(\b\w+$)"
For Each c In Selection
c.Offset(0, 1).Resize(1, 3).ClearContents
If re.test(c.Text) Then
Set mc = re.Execute(c.Text)
If mc(0).submatches.Count > 0 Then
If InStr(1, mc(0).submatches(2), " ") = 0 Then
c.Offset(0, 1).Value = Trim(mc(0).submatches(0) & _
" " & mc(0).submatches(2))
c.Offset(0, 2).Value = mc(0).submatches(3)
Else
c.Offset(0, 1).Value = mc(0).submatches(0)
c.Offset(0, 2).Value = mc(0).submatches(2)
c.Offset(0, 3).Value = mc(0).submatches(3)
End If
End If
End If
Next c
End Sub
=============================================
--ron