I created this function in VBA
for you:
It will check if each letter in the name is capitalized. If so, you'll add a space before the letter in question.
Code:
Function separa_nomes(str As String) As String
Dim i As Integer, temp As String
For i = 1 To Len(str)
If i = 1 Then
temp = Mid(str, i, 1)
ElseIf Mid(str, i, 1) = UCase(Mid(str, i, 1)) Then
temp = temp + " " + Mid(str, i, 1)
Else
temp = temp + Mid(str, i, 1)
End If
Next i
separa_nomes = temp
End Function
To enable it, simply open VBE
, inserir um novo módulo
and c olar esse código
in the open window.
Afterinsertingthecode,the=separa_nomes()
functioncanbeusedinyourspreadsheets.
Ex:
EDIT:Howdoesthiscodework?
Theideaistocreateafunctionthatcountshowmanycharacterseachwordhas
Makealoopgoingletterbyletter
Iftheletterfoundisthefirstletteroftheword:savetheletterinavariablecalledtemp
anddonotputspacebefore.
Ifi=1Thentemp=Mid(str,i,1)
Iftheletterfoundisuppercase:thismeansthatIneedtoputaspacebeforeitatthetimeofsavingitinthetemp
variable.
ElseIfMid(str,i,1)=UCase(Mid(str,i,1))Thentemp=temp+" " + Mid(str, i, 1)
-
Otherwise: I only copy the letter to the variable temp
, without adding any space.
-
Else temp = temp + Mid(str, i, 1)
-
Finally, I show the result accumulated in the variable temp
in the cell where the formula was called.
That is, to change the position of the space when you find a capital letter (from before to after the uppercase letter), you must change the term:
From:
ElseIf Mid(str, i, 1) = UCase(Mid(str, i, 1)) Then
temp = temp + " " + Mid(str, i, 1)
To:
ElseIf Mid(str, i, 1) = UCase(Mid(str, i, 1)) Then
temp = temp + Mid(str, i, 1) + " "