Peter Vogt
Peter Vogt

Reputation: 373

The name that you entered is not valid" error

I define my own simple Sub

Sub test1()
    MsgBox "Hello"
End Sub

but when I try to reference it in a cell

=test1()

I get the following error prompter:

**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**

I have no named ranges and the macro is runs without problems in the Macro manager window.

**What does this error message mean?

Do I need to name macro in a certain way to be able to use it?**

Upvotes: 0

Views: 2775

Answers (1)

Parfait
Parfait

Reputation: 107587

Two things:

  • First, your Sub must be a Function.
  • Second, you need to place the code in a Module, not behind any Sheet or ThisWorkbook.

Upvotes: 1

Related Questions