将溢出范围传递给 VBA 时遇到问题 - 仅出现应用程序定义或对象定义的错误
我在将 Spill 数组传递给 VBA 时遇到问题。该范围由名称“ListCurJobs”和等式定义
=UNIQUE(FILTER(CtrlSht!$B:$B,CtrlSht!$B:$B<>""))
使用“=ListCurJobs”在工作表上的范围按预期返回溢出范围。
我试图使用
Sub ListJobs
Dim listCurJobs() As Variant
n = Worksheets("CtrlSht").Range("listCurJobs").Rows.Count
ReDim listCurJobs(n, 1)
listCurJobs = Worksheets("CtrlSht").Range("listCurJobs")
End Sub
This Works Fine for standard arrays 将其传递到 VBA 中,但对于溢出数组,我收到错误:应用程序定义或对象定义的错误。
编辑:跟进 - 我设法通过更改命名范围 listCurJobs 以使用偏移函数
=OFFSET(CtrlSht!$E$1,0,0,CtrlSht!$D$1)
来解决此问题,其中 CtrlSht! 计算 E 中的所有项目
$D$1 正在通过=COUNTA(E1#)
,并且 E1 具有我试图在命名范围中使用的溢出函数,即
=UNIQUE(FILTER(CtrlSht!$B:$B,CtrlSht!$B:$B<>""))
无论是什么导致了原始错误,这些额外的步骤似乎都可以避免它。
I'm having an issue passing a Spill array to VBA. The range is defined by as name "ListCurJobs" and the equation
=UNIQUE(FILTER(CtrlSht!$B:$B,CtrlSht!$B:$B<>""))
Testing the named range on the worksheet using "=ListCurJobs" returns the spilled range as expected.
I am trying to pass this into VBA using
Sub ListJobs
Dim listCurJobs() As Variant
n = Worksheets("CtrlSht").Range("listCurJobs").Rows.Count
ReDim listCurJobs(n, 1)
listCurJobs = Worksheets("CtrlSht").Range("listCurJobs")
End Sub
This works fine for standard arrays, but with the spill array I get the error : Application-defined or object-defined error.
EDIT: Follow up - I managed to fix this by changing the named range listCurJobs to use an Offset function
=OFFSET(CtrlSht!$E$1,0,0,CtrlSht!$D$1)
where CtrlSht!$D$1 is counting all items in E via
=COUNTA(E1#)
and E1 has the spill function that I was trying to use in the named range i.e.
=UNIQUE(FILTER(CtrlSht!$B:$B,CtrlSht!$B:$B<>""))
Whatever is causing the original error, these additional steps seem to avoid it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法通过更改命名范围
listCurJobs
以使用Offset
函数来解决此问题:其中
CtrlSht!$D$1
正在计算 < 中的所有项目code>E via:并且
E1
具有我试图在指定范围内使用的spill
函数;即,无论导致原始错误的原因是什么,这些附加步骤似乎都可以避免它。
I managed to fix this by changing the named range
listCurJobs
to use anOffset
function:Where
CtrlSht!$D$1
is counting all items inE
via:And
E1
has thespill
function that I was trying to use in the named range; i.e.,Whatever is causing the original error, these additional steps seem to avoid it.