I need to add spaces to the beginning of my texts which are numbers

D

Demetria Jones

example I have various account numbers as texts from 4 to 7 digits. I
need to make all account numbers 10 digits long with spaces at the
beginning. Another example....
_ _ _ 1234567.
 
G

Gord Dibben

Sub fill_spaces_left()
Dim s As String
Dim cell As Range
For Each cell In Selection
With cell
.NumberFormat = "@"
.HorizontalAlignment = xlRight
s = .Value
If Len(s) < 10 Then
.Value = Space$(10 - Len(s)) & s
End If
End With
Next
End Sub


Gord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top