我昨天编写了这段代码,它运行得非常好,现在由于某种原因它抛出了运行时错误'1004'
第一部分遍历第二张表上的条目,并且在满足某些条件时,使用第二张表中的信息来引用第三张表,以将条目添加到数组中。这个数组变得很大,大约有200个条目,我不知道数组的限制是什么,所以这可能是我遇到的问题的源头。
第二部分采用该数组,并将验证列表添加到第一张表单中,并将该数组作为下拉列表。
我尝试重新编写验证列表的代码,以防万一我滑倒但无法发现问题
真正奇怪的是,昨天它一直在工作,一夜之间应该没有任何改变。
编辑说明:工作表“ A”是活动工作表,工作表“ E”和“ F”在单独的工作簿中(是的,此特定子例程引用了6个单独的工作表),LAr()先前定义为字符串数组
Edit 2注意:有趣的是,涉及大型数组的其他验证列表已经开始在不同的工作簿中引发相同的错误。有人知道有更新吗?
编辑3注意:似乎excel已更新。
i = 1
k = 0
Do While E.Cells(i, 1) <> "" 'iterate until there are no more entries'
ReDim Preserve LAr(0 To k) 'resize the array to take another value'
If E.Cells(i, 4).Value = "YES" Then 'case where the item is chooseable and reference is a string of multiple row numbers'
j = CInt(Split(E.Cells(i, 2).Value, ",")(0)) 'split off the first row number'
LAr(k) = F.Cells(j, 2).Value 'add the item name to the array'
k = k + 1 'increase the array entry counter by 1'
ElseIf E.Cells(i, 4).Value = "NO" Then 'case where item is chooseable and reference is a single row number'
j = E.Cells(i, 2).Value 'get the row number'
LAr(k) = F.Cells(j, 2).Value 'add the item name to the array'
k = k + 1 'increase the array entry counter by 1'
ElseIf E.Cells(i, 4).Value = "" And E.Cells(i, 3).Value = "NO" Then 'case where the item is not chooseable and is not a header'
j = E.Cells(i, 2).Value 'get the row number'
LAr(k) = F.Cells(j, 2).Value 'add the item name to the array'
k = k + 1 'increase the array entry counter by 1'
End If
i = i + 1 'increase the iteration counter by 1'
Loop
A.Cells(3, 7).Value = "Pick"
'create validation list with the array as the choices'
With A.Cells(3, 7).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(LAr, ",")
.InCellDropdown = True
.InputTitle = A.Cells(3, 7).Value
End With
我希望这会产生一个带有数组条目的验证列表,但是,它当前会显示错误“ 1004”