在VBA中从循环获取值的向量

我有一列可能有N / A。 我正在运行一个循环,检查是否有N / A错误,并popup一个错误的位置MsgBox。 我遇到的问题是存储错误的相应列的值。

Option Explicit Dim i As Integer Dim where As Variant Dim numbers(1 To 20) As Variant For Each i In Range("b2:b" & lastrow) If IsError(i) = True Then where = Range("B" & i.Row).Address MsgBox "Missing data was found in " & where numbers (i) = Range("D" & i.Row).Value End If Next i 

这段代码有点问题,因为得到不匹配的错误(运行时错误'13')。 请在正确的方向指出我在这里做错了什么。 谢谢

编辑:我只引用了部分代码,这就是为什么没有Sub / End Sub

 Private Const lastrow As Integer = 10 Sub GetErrors() Dim oneCell As Range Dim where As Variant Dim numbers As Variant where = vbCrLf For Each oneCell In Range("b2:b" & lastrow).Cells If IsError(oneCell.Value) = True Then where = where & Range("B" & oneCell.Row).Address & vbCrLf If (Not IsArray(numbers)) Then ReDim numbers(0) Else ReDim Preserve numbers(UBound(numbers) + 1) End If numbers(UBound(numbers)) = Range("D" & oneCell.Row).Value End If Next oneCell MsgBox "Error was found in : " & where End Sub