I need to left pad an alphanumeric string with 0s to make the numeric part of the string a total of 5 digits.
For eg:
1843Q -> 01843Q
691B -> 00691B
My problem arises when special characters are introduced in the string.
For eg:
4361G-3 -> 04361G-3
What my code does:
4361G-3 -> 04361G-
My code is
str1 = "-*"
str = Job
For i = 1 To Len(str)
chr = Mid(str, i, 1)
result = str Like str1
If IsNumeric(chr) Then
If result = False Then
strg = strg & chr
End If
ElseIf isalpha(chr) Then
If result = False Then
strg2 = strg2 & chr
End If
ElseIf chr = "-" Then
strg3 = strg3 & chr
ElseIf strg3 Like "-" Then
strg3 = strg3 & chr
ElseIf strg3 Like "[-]*" Then
strg3 = strg3 & chr
End If
Next i
strg = Format(strg, "00000") & strg2 & strg3
Job = strg
How do I need to change this to get what I want?