PDA

View Full Version : [SOLVED:] Compile Error: Expected: line number or label or statement ....



forrest
12-06-2015, 04:29 PM
I am trying to write a function in MS Office Excel. I continue to get the following error message when I test the function:

Compile error: Expected: line number or label or state or end of statement.

I reduced the function code down to the bare minimum, but keep getting the error.

Here is the function code:

Function z() As Variant
Debug.Print 123
z = 99
End Function


I am testing the function in the immediate window within Excel VBA with the following line:

=z()

I would expect to see 123 displayed following the call to the function, instead I am getting the error message above. Any ideas? Could there be a permissions / setup problem?

Thanks!

PS using MS Office Standard 2013

forrest
12-06-2015, 05:12 PM
Found the problem .... It was the way I was testing the function in the immediate window.

The proper way to test a function from the immediate window is with a question mark (?) and not an equal sign (=)

?z()

SamT
12-06-2015, 10:47 PM
:thumb