VBA - What makes a procedure "too long" ?

Dimitris254

Board Regular
Joined
Apr 25, 2016
Messages
139
What makes a procedure too long? Is it the number of local variables or the sheer size of it (ie. number of code lines)?
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
As Microsoft states, the limit is 64k; so if 700x50 is the same as 350x100 then ...
 
Last edited:
Upvote 0
thx

i've already started splitting the sub into more subs, but it's again in the same module...

since i'm new to vba, is it possible that two module communicate? so i place one sub in one module, and the rest ones in the other?
 
Last edited:
Upvote 0
Sorry it should have said
then IMHO you should have been splitting the sub anyway
not modules :(

since i'm new to vba, is it possible that two module communicate? so i place one sub in one module, and the rest ones in the other?

but yes you can i.e. Module2.zzzz where zzzz is the name of a sub in Module2.
 
Upvote 0
Ok, I checked and the module is ~7k lines (one Sub and many Private Subs called by the main).

So, should I start splitting the big subs (one is 2k) or put some of them to another module?

Most variables are declared above the main sub (so every sub sees them), but is the scope ok for subs put in another module?

So confused atm :D
 
Last edited:
Upvote 0
You don't need to put them in a different module. I have never seen Microsoft state a limit in regards to the number of lines in a module for VBA only the 64k limit on a compiled procedure (I have seen a limit stated for Visual Studio and that was 65,534 lines).

We can't give you a fixed number of lines for when you need to split a procedure as one doesn't exist and is dependent on the number of characters to start with (and I haven't seen anyone explain how the VBA compiles, maybe someone else has).

Can I just ask is the sub with over 2000 lines recorded code?

See the link below for scope of variables.

Understanding Scope
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,469
Latest member
Kingwi11y

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