VBA为什么我的下标超出范围?

时间:2017-04-16 18:20:25

标签: vba excel-vba conditional excel

我使用下面的代码解析字符串并将其中的部分设置为数组。但是,我在下面指定的行上得到了一个超出范围错误的下标。我能做错什么?

vals = Array("", "", "", "", "", "", "", "", "", "", "", "", "", "", "")

Set r = Range("B2").End(xlDown)

For Each x In Range("B2", r)
    k = 0

    For i = 1 To Len(x)
        char = Mid(x, i, 1)

        Select Case Asc(char)
            Case 48 To 57
                ' Error on line below (Run-time error9: Subscript out of range)
                vals(k) = vals(k) + char
            Case Else
                Erase vals
                k = k + 1
        End Select
    Next i

    Set cll = x.End(xlToLeft)

    cll.Value = vals(0) + "-" + vals(1) + "-" + vals(2) + "T" + vals(3) + ":" + vals(4) + ":" + vals(5) + "Z"
Next x

0 个答案:

没有答案