将溢出范围传递给 VBA 时遇到问题 - 仅出现应用程序定义或对象定义的错误

发布于 2025-01-09 02:04:11 字数 835 浏览 1 评论 0原文

我在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩耳倾听 2025-01-16 02:04:11

我设法通过更改命名范围 listCurJobs 以使用 Offset 函数来解决此问题:

=OFFSET(CtrlSht!$E$1,0,0,CtrlSht!$D$1)

其中 CtrlSht!$D$1 正在计算 < 中的所有项目code>E via:

=COUNTA(E1#)

并且 E1 具有我试图在指定范围内使用的 spill 函数;即,

=UNIQUE(FILTER(CtrlSht!$B:$B,CtrlSht!$B:$B<>""))

无论导致原始错误的原因是什么,这些附加步骤似乎都可以避免它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文