Solved

Modules

Posted on 2014-03-10
3
215 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

930 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

10 Experts available now in Live!

Get 1:1 Help Now