|
Sub Main()
Dim ar(), a, br(), b
Dim x1 As Variant, x2 As Variant
Dim s$, n&, i&
Rem 指定数据源b3:b7
ar = Range("b3:b7").Value
ReDim br(1 To 1)
For Each x1 In ar
a = Split(x1, "/")
s = Split(a(0), "-")(0)
For Each x2 In a
If InStr(x2, "-") = 0 Then
n = n + 1
ReDim Preserve br(1 To n)
If Len(x2) = Len(s) Then
br(n) = x2
Else
br(n) = Left(s, Len(s) - Len(x2)) & x2
End If
Else
b = Split(x2, "-")
If Len(b(0)) < Len(s) Then
b(0) = Left(s, Len(s) - Len(b(0))) & b(0)
End If
If Len(b(1)) < Len(s) Then
b(1) = Left(s, Len(s) - Len(b(1))) & b(1)
End If
For i = CLng(b(0)) To CLng(b(1))
n = n + 1
ReDim Preserve br(1 To n)
br(n) = Format(i, String(Len(s), "0"))
Next
End If
s = br(n)
Next
Next
Rem 指定输出第一个单元格 H3
With Range("h3").Resize(n)
.NumberFormatLocal = "@"
.Value = Application.Transpose(br)
End With
End Sub |
|