VBA中的Split()给出了Type Mismatch错误

时间:2014-09-10 15:54:35

标签: arrays vba excel-vba excel

我在下面的代码中有一些错误,请有人可以帮助我...... VBA让我感到遗憾的是,当我使用函数len时,仪器是我无法获得长度的无效限定符( )没有任何错误,但在功能分裂发生!VBA让我感到遗憾的是类型不匹配。

Sub Getinstrument()
 Dim instrument As String
 Dim splitinstrument() As String
 Dim i As Integer
 Dim removespax As Integer
 Dim tam As Integer
 removespax = -1
 instrument = Range("E3")
 splitinstrument() = Split(instrument)
 tam = instrument.Lenght - 1
 For i = 0 To tam
    If splitinstrument(i) <> ""  Then
       removespax = removespax + 1
       splitinstrument(removespax) = splitinstrument(i)
    End If
 Next
 ReDim Preserve splitinstrument(removespax)
 MsgBox splitinstrument()
End Sub

1 个答案:

答案 0 :(得分:1)

由于你希望Tam遍历数组,你实际上想要这个

tam = UBound(splitinstrument)

而不是

tam = instrument.Lenght - 1