modules vs code within sheets

andyjames

Board Regular
Joined
May 15, 2007
Messages
133
can someone tell me what the benefit to having multiple modules is and on top of this what is the benefit of putting code within a module and not just behind the worksheet?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
andy

Well having multiple modules is really only an organisational thing and is usually just down to personal preference.

As to code in worksheet modules, that should normally be only code pertaining to that particular worksheet, normally event code such as Worksheet_Change.

There are other considerations about where you locate code, for example the scope of variables.
 
Upvote 0
As Norie said, general code modules and worksheet / workbook modules are not the same thing.

Use a worksheet module for:
Code that needs to respond to events like changing a cell value or moving to another cell / range

Use the workbook module for:
Code that responds to global things like opening, closing, printing or saving a workbook

Use general modules for:
Everything else

Denis
 
Upvote 0

Forum statistics

Threads
1,225,335
Messages
6,184,335
Members
453,227
Latest member
Slainte

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
Back
Top