Excel – How to trigger an Excel macro by hovering a mouse over a cell

microsoft excelvba

I have not been able to figure out how to run an Excel macro by moving
my mouse over one or more cells in my spreadsheet.

Best Answer

Whilst there is no formal OnMouseOver event, you can put together a VBA hack to get around it. It involves using the HYPERLINK function. There's more detail here, but in summary:

If you create a new VBA module and then add a User Defined Function to do what you want:

Public Function OnMouseOver()
 Sheet1.Range("A2").Value = "You hovered over a cell"
End Function

You can then access this via a HYPERLINK call:

=IFERROR(HYPERLINK(OnMouseOver(),"Click here"), "Click here")

Note that it's wrapped inside an IFERROR to avoid a #VALUE! error message because your function isn't supposed to update a cell (but gets away with it as it's called within HYPERLINK).

Related Question