I am working with cell values in a format of "XXXX-000-000-000".
I'm having trouble keeping the zeroes in the right places.
For example:
dim ir as range
ir = "AD12-002-020-100"
ir1 = InStr(ir, "-")
ir2 = InStrRev(ir, "-")
ir.Offset(0, 1) = Mid(ir, ir1 + 1, ir2 - ir1 + 3)
Which gives me: 002-020-100
Suggestions? Thank you in advance!
Consider:
Sub dural()
Dim s As String
s = "AD12-002-020-34"
s = Replace(s, "-0", "-")
s = Replace(s, "-0", "-")
ary = Split(s, "-")
ary(0) = ""
s = Mid(Join(ary, "-"), 2)
MsgBox s
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With