By: Sishir Roy

In reply to LILY.

Hello LILY,
The formula used in the section “How to Include Space Between Numbers and Text in Excel” is a complex formula designed to insert a space after the rightmost numeric sequence in the text in a cell and then trim any extra spaces. It does not insert a space before the numeric sequence and only inserts a space after the rightmost numeric sequence. For example, you can see the image below.

The issue you are facing might be due to certain functions not working correctly in your Excel version. Consider using the latest version to avoid these problems.
However, the formula in the provided section does not insert space before the numeric sequence, making it less versatile. If you wish to insert a space between text and numbers regardless of the order of the numeric sequence, I can provide you with a VBA code to address this. If you want to insert a space before and after each numeric sequence without spaces between individual digits, you can use the following VBA function:

Function InsertSpacesAroundNumbers(inputText As String) As String
Dim outputText As String
Dim i As Integer
Dim num As String
Dim insideNumericSequence As Boolean

outputText = ""
insideNumericSequence = False

For i = 1 To Len(inputText)
num = Mid(inputText, i, 1)

If IsNumeric(num) Then
If Not insideNumericSequence Then
outputText = outputText & " "
insideNumericSequence = True
End If
outputText = outputText & num
Else
If insideNumericSequence Then
outputText = outputText & " "
insideNumericSequence = False
End If
outputText = outputText & num
End If
Next i

outputText = Trim(outputText)

Do While InStr(outputText, " ") > 0
outputText = Replace(outputText, " ", " ")
Loop

outputText = Trim(outputText)
InsertSpacesAroundNumbers = outputText
End Function

To use this, open the VBA launcher by pressing the Alt+F11 button on your keyboard.
Click on the Insert button and choose the Module option.
In the Module section, paste the provided VBA code.

After that, go back to your Excel file, and type the function name ‘=InsertSpacesAroundNumbers‘. You will find the function name in the function list. Put the cell reference in the function argument and press Enter.

As a result, it will insert a space before and after each numeric sequence without inserting spaces between individual digits.

Regards,
Sishir Roy