Locked lesson.
About this lesson
Editing the previously recorded code in order to remove unnecessary objects.
Exercise files
Download this lesson’s related exercise files.
Cleaning up recorded code.xlsm26.4 KB Cleaning up recorded code - Completed.xlsm
26.7 KB
Quick reference
Cleaning up recorded code
Learning what elements are required in recorded code.
When to use
When you want to clean up code to reduce screen flashing, make it run more efficiently, and be more legible
Instructions
Structure Review
- Keywords are listed in blue, code comments in green and all other code in black
- The routine with begin with Sub Name() and completes with End Sub
- All code follows the Object Model structure, linked together with the period character
Cleaning the Code
It is a good practice to clean the code to get rid of extraneous garbage. Key things to look for:
- When one line ends with .Select and the next starts with Selection, this can generally be shortened
- When one line ends with .Select and the next starts with ActiveCell, this can generally be shortened
- The line Application.CutCopyMode = False can generally be removed
- Some parameters added to the end of lines like .PasteSpecial may also be able to be removed
Hints & tips
- Once done modifying, save your workbook then try to run the macro
- Saving first gives you a fall back point if it doesn't work
- Comment out entire lines by putting an apostrophe (single quote) in front
Lesson notes are only available for subscribers.