Note, however, that you should not call macros unnecessarily because they slow down the performance of Excel.
ActiveCell is one of the key cells. To accomplish this, use the
Intersect method on the ActiveCell and the range containing the key cells to verify the ActiveCell is one of the key cells. If the ActiveCell is in the range containing the key cells, you can call the macro.
To create the Visual Basic macro:
- Right-click the Sheet1 tab and then click View Code.
The module sheet behind Sheet1 is opened.
- Type the following code into the module sheet:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("A1:C10")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Display a message when one of the designated cells has been
' Place your code here.
MsgBox "Cell " & Target.Address & " has changed."
- Click Close and Return to Microsoft Excel on the File menu.
ID članka: 213612 - posljednja izmjena: 23. sij 2007. - verzija: 1