2

Here is what happened. I am just a beginner, and i was watching a tutorial video today. At 2:58, the guy in the video just tested the function and it returned a value.

I did the exact same thing as following:

Function customDate() As String  
    customDate = Format(Date, "dddd dd mmmm yyyy")
End Function

And test this in the immediate window with the following command:

?customDate

the immediate window produced a blank line.

However, if i do this with a built-in function such as:

?Date

it will work and give me a value.

My question is: how do I test my own function in that window.

Malick
  • 6,252
  • 2
  • 46
  • 59
Atom Luo
  • 23
  • 2
  • BTW, when I step into this function or use this in another macro, it actually returns the value to other macros. it's just I cannot see the print result of my own function in the immediate window – Atom Luo Jul 27 '16 at 02:52
  • And apparently, my excel does not recognize my own function coz I cannot find my functions while trying to insert my functions in excel – Atom Luo Jul 27 '16 at 03:11
  • Seems like problem solved. This happens if i put my code under the worksheets. If i copy&paste my code into a new module, everything works fine – Atom Luo Jul 27 '16 at 03:22
  • User Defined Functions (**UDF**) that are in a normal module can only be called if it's loaded, either by AddIn, StartUp files. – PatricK Jul 27 '16 at 22:32

1 Answers1

0

This happens if i put my code under the worksheets. If i copy&paste my code into a new module, everything works fine

Yes, the code has to be in the proper place in order to reference it from the immediate window.

Please see these other questions for more information regarding where code belongs.

Put Excel-VBA code in module or sheet?

What difference does it make if one runs a VBA code in `Sheets`, in `ThisWorkbook`, and in `Modules`?

Community
  • 1
  • 1
Alexis Olson
  • 38,724
  • 7
  • 42
  • 64