I have an Excel sheet with a column of names eachnmae begins with firstname capitalize and lastname capitalized. like so JohnSmith
I like to know if there's a way in excel to take JohnSmith and make it John Smith . Please help
Thank you
I have an Excel sheet with a column of names eachnmae begins with firstname capitalize and lastname capitalized. like so JohnSmith
I like to know if there's a way in excel to take JohnSmith and make it John Smith . Please help
Thank you
The best answer would be to use the macros in the excel.
Function AddSpaces(pValue As String) As String
Dim xOut As String
Dim iCounter As Integer
Dim xAsc As Variant
xOut = VBA.Left(pValue, 1)
For iCounter = 2 To VBA.Len(pValue)
xAsc = VBA.Asc(VBA.Mid(pValue, iCounter, 1))
If xAsc >= 65 And xAsc <= 90 Then
If VBA.Mid(pValue, iCounter - 1, 2) = "ID" Then
'StrComp(str1, str2, vbTextCompare)
xOut = xOut & VBA.Mid(pValue, iCounter, 1)
Else
xOut = xOut & " " & VBA.Mid(pValue, iCounter, 1)
End If
Else
xOut = xOut & VBA.Mid(pValue, iCounter, 1)
End If
Next
AddSpaces = xOut
End Function
Not my code originally, copied from elsewhere, changed few variables to support explicit declaration of variables.
As already suggested you may use multiple formulate listed in the thread linked to by @Derrik, but I think they all look really long and cumbersome. My personal favourite is:
=trim(REGEX.SUBSTITUTE(A1,"([A-Z])"," [1]"))
This requires Morefunc Addon (see below, it has a host of other useful functions too)
MOREFUNC ADDON
From Derik's link, you could use this array formula (means you have to confirm it with ctrl+shift+enter instead of just enter):
=MIN(IF(ISERROR(FIND(CHAR(ROW(INDIRECT("65:90"))),C2,2)),"",FIND(CHAR(ROW(INDIRECT("65:90"))),C2,2)))
Though I modified it to start at the second character. This will give you the position of the first capital, ignoring the first character. So if C2 is "JohnSmith" this will give you 5, because the S is in the 5th position, in cell D2.
Now that you know where the last name starts, you can piece the full name with space together using in E2:
=LEFT(C2,D2-1)&" "&RIGHT(C2,LEN(C2)-D2+1)
This takes the left 5-1=4 characters John, concatenates it with a space, and the last name which is the right 9-5+1=5, since 9 is the length of the whole name, which is Smith, so you end up with "John Smith".