简体   繁体   English

你能在这个简单的 Excel VBA 语法中找到我的错误吗?

[英]Can you find my error in this simple Excel VBA syntax?

I am following this tutorials example for my Excel sheet, and getting Run-time error '1004': Application-defined or object-defined error.我正在为我的 Excel 工作表遵循本教程示例,并收到运行时错误“1004”:应用程序定义或对象定义错误。

Here is my VBA.这是我的 VBA。

Private Sub Worksheet_Calculate()
Worksheets("Input Quantities").Range("B51").Validation.InputMessage = Worksheets("Input Quantities").Range("B42")
End Sub

Notes (preserving the comments in an answer):注释(保留答案中的注释):

  1. This code will fail if Range("B51") doesn't have any validation applied.如果Range("B51")没有应用任何验证,此代码将失败。 ( your original error ) 你原来的错误
  2. Since this is in the worksheet's code-behind, you can use Me instead of Worksheets("Input Quantities") .由于这是在工作表的代码隐藏中,您可以使用Me而不是Worksheets("Input Quantities") ( fixes the subscript out of range error - probably a misspelling of the sheet name, or a trailing space ). 修复下标超出范围错误 - 可能是工作表名称拼写错误或尾随空格)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM