【发布时间】:2016-02-27 17:47:21
【问题描述】:
有人可以解释为什么会这样吗?我有一个数组变量 Loans(),它存储了几个短字符串,稍后我需要使用这些短字符串来格式化数据透视表。这些值从“基金列表”表中存储。然后工作表被删除,但我仍然需要使用这些值。当我在删除工作表后尝试使用 Loans() 变量时,Excel 返回了一个 object required 错误。我发现解决这个问题的方法是不删除工作表,但有人知道这是为什么吗?相关代码如下。
Sheets("Fund List").Select
' some code
Dim Loans() As Variant
Dim index As Integer
If LN > 0 Then
ReDim Loans(LN - 1)
index = 0
For i = 1 To LastRow
If Range("H" & i).Value = 3 Then
Set Loans(index) = Range("A" & i)
index = index + 1
End If
Next i
End If
' some more code
Sheets("Fund List").Delete
' more code
Set objField = objTable.PivotFields("Fund")
If LN > 0 Then
For index = 0 To UBound(Loans)
' I get an object required error on the following line:
LNFund = Loans(index)
objField.PivotItems(LNFund).Visible = False
Next index
End If
【问题讨论】: