Option Explicit
Sub test()
Dim arr, i, j, k, t, tt, s, s1, s2, n1, n2
arr = [a1].CurrentRegion
For i = 2 To UBound(arr, 1)
s = vbNullString:
If InStr(arr(i, 1), ",") Then
t = Split(arr(i, 1), ",")
For j = 0 To UBound(t)
If InStr(t(j), "-") Then
tt = Split(t(j), "-")
Call spltchr(tt(0), s1, n1): Call spltchr(tt(1), s2, n2)
If Len(s1) = 0 Then MsgBox "error!行" & i: Exit Sub
For k = Val(n1) To Val(n2): s = s & "," & s1 & k: Next
Else
s = s & "," & t(j)
End If
Next
arr(i, 1) = Mid(s, 2)
ElseIf InStr(arr(i, 1), "-") Then
t = Split(arr(i, 1), "-")
Call spltchr(t(0), s1, n1): Call spltchr(t(1), s2, n2)
If Len(s1) = 0 Then MsgBox "error:" & i: Exit Sub
For j = Val(n1) To Val(n2): s = s & "," & s1 & j: Next
arr(i, 1) = Mid(s, 2)
End If
Next
[b1].Resize(UBound(arr, 1)) = arr
End Sub
Function spltchr(s, a, b)
Dim i
For i = 1 To Len(s)
If IsNumeric(Mid(s, i, 1)) Then
b = Mid(s, i): a = Replace(s, b, vbNullString)
Exit Function
End If
Next
MsgBox "error!"
End Function
|