- Use Option Explicit to force thyself to declare variables and prevent
total = totol + 50 ' which would run fine otherwise - Declare variables just prior to using them for the first time - makes it easy, when reading the code to figure out why they enter the picture
- Indent your code. Even Do Knuth agrees with this one
- Use enumerated data type variables to eliminate magic constants - you basically give things names and, as Patrick Winston says, when you name things, you get power over them
- DRY! Don't repeat yourself. Use modules to keep your code manageable. Make changes in one place!
- Same as (2) above - declare just prior to use to reduce effort needed in debug
- Avoid over-referencing cells.
bad: ws.Cells(2, 1) = ws.Cells(2, 1) = ws.Cells(2, 4)
use aliases!
Good:
Dim result As Long, bonus AS Long
result = result + bonus
And,
- Same as (4) above!
No comments:
Post a Comment