Creating worksheet-related events
The next logical step will be to create events that influence only worksheets. This recipe will discuss the principles behind these events.
Getting ready
Open Excel and activate a new workbook. Save the file as a macro-enabled file on your desktop and call it Worksheets
. Enter the following data in Sheet1:
Finally, press Alt + F11 to switch to the VBA Editor.
How to do it…
The first worksheet event we will create is the SelectionChange
event. The steps are virtually the same as with the workbook event handler procedure:
- Double-click the worksheet object in Project Explorer, Sheet1.
- In the code window that appears, click on the drop-down arrow on the left, and choose the object that you're coding for; Worksheet.
- This will automatically generate the default event for this object, which is the
SelectionChange
event. - Insert two lines of code into the...