Adding Spaces Between Words in the Employee CSV Import/Export File
This article walks through how to inject spaces between words in the Employee CSV sheet using Excel.
Here are some examples of what this process will accomplish:
- "HumanResources" instead of "Human Resources"
- "VicePresident" instead of "Vice President"
- Open the Employee CSV file you wish to modify in Excel.
- Hold down ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
- Click Insert > Module, and paste the following code in the Module window.
VBA code: Insert spaces before capital letters
Function AddSpaces(pValue As String) As String
'Update 20140723
Dim xOut As String
xOut = VBA.Left(pValue, 1)
For i = 2 To VBA.Len(pValue)
xAsc = VBA.Asc(VBA.Mid(pValue, i, 1))
If xAsc >= 65 And xAsc <= 90 Then
xOut = xOut & " " & VBA.Mid(pValue, i, 1)
Else
xOut = xOut & VBA.Mid(pValue, i, 1)
End If
Next
AddSpaces = xOut
End Function - Save and close this code.
- Enter the "formula =addspaces(A1)" into a blank cell beside your data. The screenshot below is an example.
- Highlight the range to which you want to apply the formula. The spacing will update, as seen below.