View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
wmdmurphy wmdmurphy is offline
external usenet poster
 
Posts: 12
Default Sub or function not defined

Dave,

Yes, I placed the functions in the General section of the worksheet, and
also tried placing them in the General section of the workbook, but got the
error message either way.

Month and Year in my worksheet are both combo box dropdowns so the user can
only enter valid months and years. But I would like to default them when
the workbook is opened to values like May and 2009, based on the current
date.

You are right that the Me!Month comes from my Access programming background.
In Excel how would I reference the Month cell for example, if it can only
accept values from the dropdown list?

Bill


"Dave Peterson" wrote in message
...
Did you put the GetMonth in a General module?

But I'm confused about what Me!Month is supposed to be.

If you're working inside a userform and have a textbox named Month, then
maybe:

Me.Month.value = getmonth

(the exclamation is a holdover from your Access days???)

If you're trying to use that function in a cell in the same workbook that
owns
that function:

=getmonth()

If you're trying to use that function in a cell in a different workbook:

=book1.xls!getmonth()



wmdmurphy wrote:

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


--

Dave Peterson