Very simple question on functions

buffalo

Board Regular
Joined
Jun 19, 2003
Messages
183
Hi,

I have still not figured out where to put the VBA code for functions in excel.

I click Alt + F11 and get to the VBA code part, I can write the Sub's and when i click the Run button they run well.

But not so for functions. ONLY when I open a new 'Module' and write my function in that, then i can work the fucntion from the worksheet.

QUESTIONS:
....Where is the right place to write fucntions?
....What is module useful for?

thanks
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

earlyd

Well-known Member
Joined
Dec 10, 2002
Messages
1,199
I get the same thing with Alt F11.

To write a function, you can choose Tools...macro....macros.....then type in a macro name, click create and change the sub to a function.

Not very elegant but it works.
 

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
buffalo said:
Hi,

I have still not figured out where to put the VBA code for functions in excel.

I click Alt + F11 and get to the VBA code part, I can write the Sub's and when i click the Run button they run well.

But not so for functions. ONLY when I open a new 'Module' and write my function in that, then i can work the fucntion from the worksheet.

QUESTIONS:
....Where is the right place to write fucntions?
....What is module useful for?

thanks

I guess the first thing you need to understand is what a module is. Think of a module as a container. There are worksheet modules, the ThisWorkbook module, and then the...um....module modules. I would recommend that you use the worksheet and ThisWorkbook modules for EVENT macros (macros that automatically run when a particular event occurs.) If you want a macro or function to be available to the entire workbook, you will put it in a module module. You might ask, "Why not put it in the ThisWorkbook module if you want code to be run anywhere in the workbook?" The ThisWorkbook module is designed for workbook events. The ThisWorkbook is something specific to Excel VBA. Regular VB wouldn't have a ThisWorkbook sort of thing. It would have the module modules though.

Did I make this more confusing than it needs to be?
 

Watch MrExcel Video

Forum statistics

Threads
1,130,448
Messages
5,642,218
Members
417,262
Latest member
andrewd1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top