@Rick
I tested only with your offered strings:
1,5,9-12,20-18
1 5 9-12 20-15
1,5 9-12, 20 - 15
AB8-AB12
CD3 - CD7 K4, P2-P5 JM8 - JM3
ABCD1-9
XYZ3 - 7
This doesn't error out on my system however.
Code:Sub tst() MsgBox F_expand("a9 - 4 x4,m9 r7 b4 - b8,c4-1") End SubCode:Function F_expand(c00) sn = Split(Replace(Replace(Replace(Trim(c00), " -", "-"), "- ", "-"), ",", " ")) For j = 0 To UBound(sn) If InStr(sn(j), "-") Then c01 = "" c02 = "" If Val(sn(j)) = 0 Then c01 = Left(sn(j), InStr(sn(j), "-") - Len(Format(Val(StrReverse(Left(sn(j), InStr(sn(j), "-"))))))) sp = Split(Replace(sn(j), c01, ""), "-") If Val(sp(0)) > Val(sp(1)) Then c02 = Val(sp(0)) + Val(sp(1)) & "-" sn(j) = c01 & Join(Evaluate("transpose(" & c02 & "row(" & sp(0) & ":" & sp(1) & "))"), "," & c01) End If Next F_expand = Join(sn, ",") End Function




Reply With Quote
Bookmarks