I'm trying to add spaces before numbers. The first code worked fine, 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 the loop below. But it goes into infinite loop , because VBA does not understand that the number of characters has 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