Microsoft Office Tutorials and References
In Depth Information
Worksheet Events — ​an Overview
Activating a worksheet
Changing a cell value
Clicking a hyperlink
Right-clicking a cell
Calculating a formula
With VBA’s event programming capabilities, you can tap into Excel’s recognition of when an event
occurs and what kind of event it is. This allows you to write VBA code that will execute based on
whichever event(s) occur that you want to monitor. This book primarily concentrates on events at two levels:
Worksheet-level events , which are introduced in this lesson.
Workbook-level events , which are introduced in the next lesson.
WorksHEET EVEnTs — An oVErViEW
Worksheet-level events occur for a particular worksheet. As you might imagine, events occur when
something happens to a worksheet, such as entry of new data into a cell, or a formula being calculated,
or the worksheet being activated or deactivated. Event code that is associated with any particular
worksheet has no direct effect on events that take place on other worksheets in that or any other workbook.
Where does the Worksheet Event code go?
You’ve become familiar with the concept of modules as being containers for the macros that you or the
Macro Recorder creates. You’ll be pleased to know that each worksheet already comes with its own
built-in module, so you never need to create a module for any worksheet- or workbook-level procedure
Worksheet event code always goes into the module of the worksheet for which you are monitoring the
event(s). Regardless of the Excel version you are using, the quickest and easiest way to go straight to a
worksheet’s module is to right-click its sheet tab, and select View Code, as shown in Figure 11-1.
To access the worksheet’s module quickly,
right-click the sheet tab and select View Code.
figurE 11-1
Search JabSto ::

Custom Search