View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default Sub or function not defined

The keyword Me refers to the object holing the executing code, ThisWorkbook,
Sheet, Userform, etc.

It looks like you are trying to use Month as both a constant and a variable.
That will not work. You should use something like myMonth for the variable.
Your function needs to be in the general code Module1 for it to be
recognized when called from code located elsewhere.

"wmdmurphy" wrote in message
...
I would like to add some VBA functionality to a workbook in order to set a
default value for a cell named Month and another named Year. I've opened
the visual basic editor and added some code like the following:

Function GetMonth()
GetMonth = Month(Date)
End Function

Me!Month = GetMonth()

When I try to run these functions I get an error message "Sub or function
not defined". Are there other steps needed to activate visual basic in
this workbook?

Also, can named cells be referred to as Me as in the above example?

Bill