View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Opinion on Size/Length of Macro/Function/Sub

Where to begin... 600 lines is almost definitly too long. How long should it
be. That is another matter. One theory is that one procedure/function should
do one thing. It makes the procedure easy to follow and document. Generally
speaking all of the code will fit on one printed page and that will make it
easy to debug. That being said this is not always feasable or desirable. My
general rule is that a procedure should do one type of thing. By that I mean
things like data extraction, data manipulation, formatting, printing,
saving... This keeps the code nicely compartmentalized. If something goes
wrong I can quickly narrow it down to the procedure that is causing the
problem. The other reason to keep your functions down to doing one thing or
one type of thing is that it will allow you to reuse your code. A bunch of
different procedures may do a bunch of different things but they may all call
the same save procedure for instance.

As with all rules these rules are made to be broken. But before you go
breaking rules make sure you understand why the rule is there and that you
have a good reason for breaking it. When to break the rules is one of the
hardest rules to follow.
--
HTH...

Jim Thomlinson


"Rob" wrote:

Should I have 13 seperate Macros or one long Sub/Macro??

I was wondering if I can get some opinions on this subject. The reason is
because I have a Workbook that has a Macro/Sub that has 600 lines of code in
it. But here's the thing... The code I have performs like 13 different
routines that could be broken out seperately.

Your opinions are most certainly valuable to me so please enlighten me.


Thanks Tons.
Rob