-1

我需要从用户表单(VBA、Excel)中解析数字范围。例如:{1-3,5,9} -> {1,2,3,5,9,}

这个问题已经在这里讨论过: Advanced parsing of numeric range from string

任务很标准,有没有现成的VBA解决方案?

4

1 回答 1

1

我假设包围的大括号不是字符串的一部分。考虑以下 UDF:

Public Function DashFiller(sIn As String) As String
    Dim N As Long, NN As Long
    DashFiller = ""
    ary = Split(sIn, ",")
    For N = LBound(ary) To UBound(ary)
        If InStr(1, ary(N), "-") > 0 Then
            ary2 = Split(ary(N), "-")
            ary(N) = ary2(0)
            For NN = ary2(0) + 1 To ary2(1)
                ary(N) = ary(N) & "," & NN
            Next NN
        End If
    Next N
    DashFiller = Join(ary, ",")
End Function

所以如果 A1 包含:1-2,3,4,5,9-12

B1 包含:=DashFiller(A1)

然后 B1 将显示:1,2,3,4,5,9,10,11,12

于 2013-09-07T20:13:12.507 回答