Formatting your VBA code

shadow12345

Well-known Member
Joined
May 10, 2004
Messages
1,238
Im awful at keeping my code tidy, and the indents and tabs go all over the place where i copy and paste bit around.

I have two quesitons...
Is there a free VBA code Formater anyone knows of?

Is there a standard convention on how to arrange the code in the first place?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Smart Indenter - invaluable.
There are lots of conventions for coding. What specifically do you mean by "how to arrange the code"?
 
Upvote 0
I mean like Dim statement far left, with statement one tab in , If statement two tabs in...

and so on.
 
Upvote 0
The usual convention is that you go one tab in as you nest blocks, rather than having different tab stops for different blocks. Up to you whether you add tabs before your Dims or not (I do). The addin has various options you can set up to get the output the way you like. (my general rule is that it doesn't really matter what convention you use as long as you are consistent with it)
 
Upvote 0
Ill have a look at it... pick something and go with it.

It was fine when they were small but so of them are pages long and need tidying up.

Cheers
 
Upvote 0
That inderter looks slicker than greased cat shi... (poop)!
Thanks Rory (...Mary?:laugh:) I'll have to check that out.
"(my general rule is that it doesn't really matter what convention you use as long as you are consistent with it)" - and it's (relatively) easy to decipher.

While I'm going to check out that add-in, I do believe indenting manually has its value. I generally go through the code when it's finished, indenting manually just to make sure everything is as it should be (mostly code-wise, not indent-wise)
 
Upvote 0
That inderter looks slicker than greased cat shi... (poop)!
Thanks Rory (...Mary?:laugh:) I'll have to check that out.
"(my general rule is that it doesn't really matter what convention you use as long as you are consistent with it)" - and it's (relatively) easy to decipher.

While I'm going to check out that add-in, I do believe indenting manually has its value. I generally go through the code when it's finished, indenting manually just to make sure everything is as it should be (mostly code-wise, not indent-wise)

I thought the same thing about that indenter add-on... but then it wouldn't let me add it to my work computer:( So I guess I'll just have to stick with the manual indenting.
 
Upvote 0
I do believe indenting manually has its value. I generally go through the code when it's finished, indenting manually just to make sure everything is as it should be (mostly code-wise, not indent-wise)

One of the things I like about the addin is that after you run it on a procedure, if the End Sub line is indented at all, you know you've forgotten to close a block properly somewhere.
 
Upvote 0
One of the things I like about the addin is that after you run it on a procedure, if the End Sub line is indented at all, you know you've forgotten to close a block properly somewhere.

****... now I really wish I could add it on my work comp. I hate when I forgot a little "end if" somewhere and have to go through searching trying to find it... lol
 
Upvote 0
And the fact it will do an entire project in one click... :) (I'll stop rubbing it in now)
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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