An implementation of Visual Basic that is built into Microsoft products.
Hello,
Are you trying to keep the leading space visible in the cell, or only in the formula bar?
Excel trims leading spaces in some cases, so set the cell format to Text before writing the value. Use VBA to force the value as text and preserve the space:
Sub AddLeadingSpaceForceText()
Dim c As Range
For Each c In Selection
If Not IsEmpty(c) Then
c.NumberFormat = "@"
c.Value = " " & CStr(c.Value)
End If
Next c
End Sub
This stores the value as text so Excel keeps the leading space instead of removing it.