Execute a macro by selecting a cell

  • Thread starter Thread starter scrabtree
  • Start date Start date
You can use the SelectionChange event procedure to trap the event raised
when the user selects a cell. For example, put the following code in the
appropriate sheet's code module, and it will run code when a user selects a
single cell in the range A1:A10

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then
Exit Sub
End If
If Not Application.Intersect(Range("A1:A10"), Target) Is Nothing Then
MsgBox "You selected: " & Target.Address
End If
End Sub
 
Back
Top