Consulting

Results 1 to 3 of 3

Thread: Compile Error: Expected: line number or label or statement ....

  1. #1
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    2
    Location

    Compile Error: Expected: line number or label or statement ....

    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
    Last edited by forrest; 12-06-2015 at 04:35 PM. Reason: added version of MS Office

  2. #2
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    2
    Location
    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()

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •