I'm writing a function which needs to look up a code of a certain length in a different range, but not all codes are the correct length. In this range, that is fixed by having extra zeroes in front of it.
So I am trying to write part of a macro that adds the 0's in front of the code until it is exactly 13 characters long (assuming it is not already 13 characters long).
For now, I have this, but I feel like it can be done better. Especially because I don't know if 10 is the shortest possible length.
Function BolS(Barc As Range) As String
Dim BarA As Range
If Len(Barc.value) = 10 Then
BarA = "000" & Barc.value
End If
If Len(Barc.value) = 11 Then
BarA = "00" & Barc.value
End If
If Len(Barc.value) = 12 Then
BarA = "0" & Barc.value
End If
If Len(Barc.value) = 13 Then
BarA = Barc.value
End If
Maybe something with 13 minus the Len(Barc.value), and then adding that many 0's?