Editing the code by changing cell references
This recipe shows you how to edit coding in the VBA Editor. It is more effective to make changes in the code, rather than deleting an entire macro and recording it again. We're going to start by deleting some redundant lines of code, before showing you how to edit code in order to bring about a visible change on the spreadsheet when the code is executed.
Getting ready
With 02_RecordMacro.xlsx
still open, use the keyboard shortcut, Alt + F11, to activate the VBA Editor.
How to do it…
For this recipe, the steps are as follows:
- In the VBA Editor, double-click on Module1 to open the code window.
- In the code window, select the second line of the executable code. Delete the line of code, as well as the empty line:
- Switch back to Excel, clear all formatting on the data and run the macro. The result is the same as with the first test.
- Next, select all the...