VBA 代码应用程序或对象错误问题

发布于 2024-09-13 10:44:42 字数 457 浏览 9 评论 0原文

我已经在 VBA 中编写了一些代码,我的代码在这一行中断,引发应用程序定义或对象定义的错误。

.Formula = "=IF(AND(chr(34) & ' & chr(34) & Criterion " & i & "'!" & cellAdress & ">=1;chr(34) & ' & chr(34) & Criterion " & i & "'!" & cellAdress & "<=4);chr(34) & ' & chr(34) & Criterion " & i & "'!" & cellAdress & ";0)"

我真的很努力检查出了什么问题,但我看起来也很好。请让我知道可能出了什么问题以及如何修复它。

谢谢

I have coded some code in VBA my code breaks at this line raising Application defined or object defined error.

.Formula = "=IF(AND(chr(34) & ' & chr(34) & Criterion " & i & "'!" & cellAdress & ">=1;chr(34) & ' & chr(34) & Criterion " & i & "'!" & cellAdress & "<=4);chr(34) & ' & chr(34) & Criterion " & i & "'!" & cellAdress & ";0)"

I really tried to check what is wrong but it looks fine too me. Please let me know what could be wrong and how to fix it.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

勿挽旧人 2024-09-20 10:44:42

我认为你想要

.Formula = "=IF(AND('Criterion " & i & "'!" & cellAdress & ">=1;'Criterion " & i & "'!" & cellAdress & "<=4);'Criterion " & i & "'!" & cellAdress & ";0)"

至少这会产生一个有效且合理的细胞公式,而你的则不然。

cellAdress 设置为 "A1" 并将 i 设置为 10 时,结果将是:

"=IF(AND('Criterion 10'!A1>=1;'Criterion 10'!A1<=4);'Criterion 10'!A1;0)"

I think you want

.Formula = "=IF(AND('Criterion " & i & "'!" & cellAdress & ">=1;'Criterion " & i & "'!" & cellAdress & "<=4);'Criterion " & i & "'!" & cellAdress & ";0)"

At least this produces a valid and sensible cell formula, your's does not.

With cellAdress set to "A1" and i set to 10, the result would be:

"=IF(AND('Criterion 10'!A1>=1;'Criterion 10'!A1<=4);'Criterion 10'!A1;0)"
雨巷深深 2024-09-20 10:44:42

好吧,我现在明白了。在我运行之前,我的 VBA 也不会引发任何错误。也许我看这段代码太久了并且发疯了。我的单元格地址包含 D18,i 包含 1。我有一个名为 Criterion 1 的工作表,该工作表中的单元格的值为 2(当它为空时我也尝试过)。仍然出现此错误,我不知道是什么原因造成的。

Ok I understand it now. My VBA also doesn't raise any errors until I run. Maybe I'm looking on this code for too long and go crazy. My cell Address contains D18 and i contains 1. I do have a sheet called Criterion 1 and the cell in this sheet has a value of 2 (i also tried when it was empty). Still this error is raised and I don't know what is causing it.

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