Don't repeat yourself

Referenced in: 

DRY (don't repeat yourself). Programs often have blocks of code that are similar. Like input validation, where the same checks are applied to multiple input cells.

Don't copy-and-paste. Instead, make a Sub for the similar code. Use params to specify what the code should do differently each time it is called. E.g., what cell to check, what error message to show.


  • Helps you be more productive.
  • Makes code easier to test and debug, since there is only one copy of potentially broken code.
  • Makes it easier to change what the program does. See Make programs easy to change.

The page Reusing code has an example.