Excel:将范围转换为数字

时间:2014-08-12 01:41:01

标签: excel vba

我是Excel VBA编码的新手。我的数据看起来像12,14,18,20-25,27,30,但我希望成为12,14,18,20,21,22,23,24,25,27,30

简单来说,将范围20-25更改为20,21,22,23,24,25

excel有办法吗?提前致谢

1 个答案:

答案 0 :(得分:1)

考虑到你在字符串中有值:

Sub asdadas()
    MsgBox SplitStr("12,14,18,20-25,27,30,34-47")
End Sub

Function SplitStr(xx As String) As String
    valu = Split(xx, ",")
    Stri = ""
    For Each nn In valu
        If InStr(1, nn, "-") > 0 Then
            For i = Left(nn, InStr(1, nn, "-") - 1) To Right(nn, Len(nn) - InStr(1, nn, "-"))
                If Stri <> "" Then
                    Stri = Stri & "," & i
                Else
                    Stri = i
                End If
            Next
        Else
            If Stri <> "" Then
                Stri = Stri & "," & Trim(nn)
            Else
                Stri = Trim(nn)
            End If
        End If
    Next
    SplitStr = Stri
End Function