Solved

Modules

Posted on 2014-03-10
3
212 Views
Last Modified: 2014-03-10
Hi All,

Today's question is just a general information question but I have never had a definitive answer.  So having said that...

Can somebody please explain to me why we should put our subs and functions in modules instead of the actual sheet itself?  Is it because we want to be able to "Call" the subs/functions from the modules and this is easier than if the sub/functions are in the sheets themselves?  Does it make the vba program run faster?

What are the benefits?  

thanks,
0
Comment
Question by:BostonBob
3 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39919272
If you want to call a macro that's in sheet code, you'll need to prefix it with the vba sheet name, which you can change, but which by default, doesn't give you a lot of information about the sheet, e.g. sheet35.Macro1

This means you need to find out first which sheet has your macro before you can call it. That makes for slower coding, but I don't believe it makes for slower execution.

In terms of code maintenance, I use workbook and worksheet codes to handle workbook and worksheet events respectively and use the modules and class modules to contain everything else. When I open someone else's files, this is also where I look to find macros so deviation from that norm would slow me down.

My 2 cents, fwiw,

Thomas
0
 
LVL 58

Expert Comment

by:Gary
ID: 39919305
nutsch sums it up pretty well but if you want a more detailed explanation/logic behind which to use.
http://www.cpearson.com/excel/codemods.htm

::no points for this::
0
 

Author Closing Comment

by:BostonBob
ID: 39919446
Thanks for the succinct answer!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now