excelvbamouseevent

Capturing the Click event in an Excel spreadsheet


How can I capture the event in Excel when a user clicks on a cell. I want to be able to use this event to trigger some code to count how many times the user clicks on several different cells in a column.


Solution

  • Check out the Worksheet_SelectionChange event. In that event you could use Intersect() with named ranges to figure out if a specific range were clicked.

    Here's some code that might help you get started.

    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
        If Not Intersect(Target, Range("SomeNamedRange")) Is Nothing Then
             'Your counting code 
        End If
    End Sub