Link macro to highlight onclick cell?

In excel 2000, is it possible to link a vba function that will be executed when a cell is clicked with the mouse?

+3
source share
2 answers

Found a solution:

Make a named range for the cells you want to capture clickevent

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.EnableEvents = False
    Application.ActiveSheet.Cells(1, 1).Value = Target.Address
    If Not Intersect(Target, Range("MyNamedRange")) Is Nothing Then 
        ' do your stuff
        Range("A1").Select
    Endif
    Application.EnableEvents = True
End Sub
+4
source

You can snap to double-click cells.

Open VBA, go to the worksheet that you want to connect to the event. Select "Worksheet" from the drop-down list in the upper left and "BeforeDoubleClick" in the upper right corner. Checking Target.Address is equal to the address of the cell you care about and call the function you need.

Something like that:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Address(True, True, xlA1) = "$A$1" Then
        Call MyDemo
    End If
End Sub

Private Sub MyDemo()
    MsgBox "Hello"
End Sub
+4

Source: https://habr.com/ru/post/1718465/


All Articles