excel vba运行时错误1004-不清楚原因

excel vba运行时错误1004-不清楚原因,excel,vba,runtime,Excel,Vba,Runtime,我通过运行以下代码获得运行时错误: For Each cell In Range("B1").EntireColumn.Cells If cell.Value = ListBox1.Value Then FIng(i) = cell.Row i = i + 1 End If Next cell For i = 0 To UBound(FIng) If Cells(FIng(i

我通过运行以下代码获得运行时错误:

    For Each cell In Range("B1").EntireColumn.Cells
        If cell.Value = ListBox1.Value Then
            FIng(i) = cell.Row
            i = i + 1
        End If
    Next cell

    For i = 0 To UBound(FIng)
        If Cells(FIng(i), 1).Value > 0 Then 'error: application defined 1004
            MsgBox (Cells(FIng(i), 1).Value)
        End If
    Next i

错误发生在注释所在的行中。我要做的是检查某个值是否在列中,然后将列行保存在数组中。下一个循环是使用此数组访问第一列中的值并显示它。它可以工作,但我收到了这个错误消息,我不知道为什么。

这是正确的第二个for循环:

For i = 0 To UBound(FIng)
    If FIng(i) > 0 Then 'error: application defined 1004
        MsgBox (Cells(FIng(i), 1).Value)
    End If
Next i

您是否尝试调试
单元(FIng(i),1)。值
?什么是“FIng”?“i”的初始值是什么?FIng被初始化为一个十元素数组。因为我只对行号感兴趣(行号总是大于零),所以我必须先检查。所有其他值均为零。但是我不明白为什么这会导致错误。啊,我想我知道这个问题。我应该只检查Fing而不是value。