Hi Guys,
I have 2 UDFs and then a sub that uses them to split a string everytime it sees a "/" and then concatenate the substrings into a new string with spaces.
My problem is that if I have more than 2 substrings, the order is not correct.
Example: EDMONDS/DAVE will output fine as DAVE EDMONDS but if I try it with EDMONDS/DAVE/STEPHEN it will only output STEPHEN DAVE EDMONDS not DAVE STEPHEN EDMONDS which is how I would like it. I am sure it is a simple change but I just can't see it.
Any help gratefully received.
Code
Function Getname(str As String, lngname As Long)
Dim v As Variant
v = Split(str, "/")
'// The -1 as arrays are 0 based.
'If UBound(v) >= lngname Then
Getname = v(lngname - 1)
'Else
' Getname = ""
' End If
End Function
Display More
Code
Sub Change_Name()
Dim Test As String
Dim Formula1, Formula2 As String
Dim name_string As String
Dim lngname As Long
Dim printname As String
On Error Resume Next
For Each x In Selection
printname = ""
name_string = x
Debug.Print Numnames(name_string)
For lngname = 1 To Numnames(name_string)
Test = Getname(name_string, lngname)
printname = Test & " " & printname
Next
x.Offset(0, 1) = printname
Next x
End Sub
Display More
Cheers,
Dave