Efficiency and Elegance

jdahls

New Member
Joined
Sep 18, 2002
Messages
3
Is there anyplace on the board where I can find some basic rules for writing VBA for Excel macros? I have made the leap from just using the macro recorder to actually typing, but the more I write the harder they are to interpret. Any tips to make them efficient and easier to maintain would be appreciated. Thanks.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi jdahls,

Welcome to the board. :)

Congratulations on stepping-up to 'proper' macros rather than just using the recorder. (remember though, if you get stuck the recorder can sometimes be very useful!).

Anyway, I don't think the board has a 'rules of VBA code' section so I'll start you off with what I'd recommend and see what the other guys add.

1. Use lots of comments in your routines. You may know what it means now but if you need to re-use a routine at a later date it may not be so clear.

2. Adopt a 'modular' approach. That is, when you have a large task to complete, try to break it down into smaller self-contained tasks. This makes it easier to check for errors.

3. Practice. If something doesn't work, try to figure out why. If you can't figure out why then post a question here on the board.

4. Look at other people's code and learn from the way that they do things. This board is a great source of knowledge and I have learned a great deal here (and am still learning!).
 
Upvote 0
Thank you Richie. For breaking up a task into smaller tasks, is it more efficient to write several subs and "call" them from within one module? Or am I better off just breaking it up visually with blank lines and comments?
 
Upvote 0
Take a look at purchasing a book on Object Oriented Programming (OOP).

Or do a search on the internet for it.

This type of programming will make things a lot easier once you get the hang of it.

Try and stay away from On-the-Fly Programming (OTFP). Its the easiest but worst programming style. Its where you just start writing code without thinking and planning the code first.
_________________
Kind regards,<font size="5"><sup><span style="text-decoration: overline">AL</span></sup><u><sub>CHARA</sub></u></font
This message was edited by Al Chara on 2002-09-19 13:06
 
Upvote 0
Just a another bit of encouragement. The macro recorder never looses it's value, however, you can accomplish sooooo much more writing your own code. Best advice is the same as Al Chara's. It will be well worth your time to get the big picture by familiarizing yourself with the structure of object oriented/based programming. For a quick start on what you are doing now, if anything, post your code and an explanation of what your trying to do. Ask for some specific advice on how you might re-write the code for improved readability, speed, and reusability in other projects.

Tom
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

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