您input的名称是无效的“错误

我定义了我自己的简单的子

Sub test1() MsgBox "Hello" End Sub 

但是当我尝试在一个单元格中引用它

 =test1() 

我得到以下错误提示器:

 **The name that you entered is not valid Reason for this: 1) The name does not begin with a letter or underscore 2) The name contains a space or other invalid character 3) The name conflicts with a Excel built in name or name of another object in the workbook** 

我没有命名的范围和macros运行macrospipe理器窗口中没有问题。

**这个错误信息是什么意思?

我是否需要以某种方式命名macros才能使用它?**

两件事情:

  • 首先,你的Sub必须是一个Function。
  • 其次,您需要将代码放在模块中,而不是放在任何Sheet或ThisWorkbook之后。