Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Opinion on Size/Length of Macro/Function/Sub

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Opinion on Size/Length of Macro/Function/Sub

As a novice programmer, I second Jim's advice. If you can modularize your
code it makes it a lot easier to manage, especially if you have a routine
with a lengthy algorithm that you need to run more than once. I cut one of
my first programs in half after I learned how to call the sub routines from a
master sub. Even if it is a file save exercise you can use a one line call
as opposed to three lines or more each time.

"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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Project - Second opinion please! Danny Excel Worksheet Functions 11 September 17th 07 11:03 PM
Create Variable Length String Dependent Upon Size List ags5406 Excel Programming 1 May 28th 06 11:30 PM
Your opinion CBrausa Excel Discussion (Misc queries) 1 May 18th 06 07:55 PM
Macro or Function to make text size to suite text Length? lbbss Excel Discussion (Misc queries) 4 December 14th 04 07:53 PM
The text length versus the cell size... shockley Excel Programming 2 September 14th 03 02:43 AM


All times are GMT +1. The time now is 08:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"