Excel VBA 数组不打印任何内容

问题描述 投票:0回答:1

我已将数组声明为

Dim weights As Variant

以下程序可以打印:

    Dim item As Variant
    For Each item In weights
        Debug.Print item
    Next item

但是以下程序没有打印任何内容:

    Dim i As Integer
    For i = LBound(weights) To UBound(weights)
        Debug.Print CStr(weights(i - 1))
    Next i

请帮忙。

我刚刚注意到以下作品:

    Dim i As Integer
    For i = LBound(weights) To UBound(weights)
        Debug.Print weights(i, 1)
    Next i

有人可以解释一下为什么吗?

excel vba
1个回答
0
投票

您应该将数组声明为

Dim weights() As Variant
© www.soinside.com 2019 - 2024. All rights reserved.