0
I’m trying to add spaces before numbers. The first code worked, but I wanted to do it in the form of loop.
Sub numeros()
numero = Range("A2").Value
n = 3
If Len(Range("A" & n).Value) = 3 Then
numero = Range("A" & n).Value
ElseIf Len(Range("A" & n).Value) = 2 Then
numero = " " & Range("A" & n).Value
ElseIf Len(Range("A" & n).Value) = 1 Then
numero = " " & Range("A" & n).Value
End If
Range("B" & n).Value = "|" & numero & "|"
End Sub
The closest I got was loop below. But he enters loop infinite, because the VBA does not understand that the number of characters passed 3.
Sub numeros2()
n = 1
numero = 1
espaço = 0
Do Until Len(numero) = 3
numero = Space(espaço) & numero
espaço = espaço + 1
Loop
Range("B" & n).Value = "|" & numero & "|"
End Sub
Daniel, sorry for the question that probably won’t be valid, but you can format the cells to be aligned right, would be the case?
– Evert