在VBScript中使用变量索引数组时类型不匹配(与工作表相关)

时间:2018-03-22 09:59:28

标签: arrays excel excel-vba indexing type-mismatch vba

我遇到了与Excel相关的VBScript的一些问题。我知道这可能是一个直接的解决方案,以后会显而易见,但无论如何:

我试图在这里实现的基本上是获取每列中最长值的长度并将它们写回数组(前16列中的每一列都有一个值)。就这么简单。

...
mlen = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
For i = 1 To 16
  rw2 = 2                        ' starting from the second row
  While Cells(rw2, i) <> ""      ' all the way until an empty field is found
    If Len(Cells(rw2, i)) > mlen(i - 1) Then mlen(i - 1) = Len(Cells(rw2, i))
    rw2 = rw2 + 1
  Wend
Next
...

然而,它给了我一个类型不匹配的&#34; mlen(i-1)&#34;在&#34;&gt;&#34;的右侧操作

任何解决方案都将非常感激。 提前致谢,祝你有个美好的一天!

1 个答案:

答案 0 :(得分:0)

tmax&lt;&gt; MLEN!

>> mlen = Array(0, 0, 0)
>> WScript.Echo mlen(0)
>> WScript.Echo tmax(0)
>>
0
Error Number:       13
Error Description:  Typenkonflikt (i.e. type-mismatch)
>>