Function reformat(s As String, splitchar As String, length As Long) As String
's is the plot string
'splitchar is the char used to separate the plots
'length is the required length
Dim a() As String
Dim x As Long
Dim y As Long
Dim result As String
a = Split(s, splitchar) 'turn the string into an array
For x = 0 To UBound(a)
If IsNumeric(a(x)) Then
a(x) = Right("0000" & a(x), length) 'just process a numeric plot
Else
y = 1
While IsNumeric(Mid(a(x), (y), 1)) 'find the first non numeric char
y = y + 1
Wend
a(x) = Right("0000" & Left(a(x), y - 1), length) & Mid(a(x), y) 'process a non-numeric plot
End If
Next
'now reassemble the string
result = ""
For x = 0 To UBound(a)
If x > 0 Then
result = result & splitchar & a(x)
Else
result = a(x)
End If
Next
reformat = result
End Function
Sub test()
MsgBox (reformat("1-2A", "-", 4))
End Sub