Mouse Hover Event in Excel
Did you know you can add a mouse hover event in excel worksheet? well, you can, and that’s pretty cool isnt it? There is a hidden trick in excel that you can use run macro when you move your mouse on worksheet
How to do it?
Well, it is so easy. First of all you need to write a function procedure in VBA, it has to be a function procedure, Sub procedure will not work. You can use the function written below.
Function CallMe(lngRow As Long, lngCol As Long) As String
Sheet1.Range(“rngCountry”).Value = Sheet1.Cells(lngRow, lngCol).Value
Second step is to call this function on worksheet by using excel native function HYPERLINK. this is how you will write your formula in order to call the UDF from VBA.
Above function will sure return an error because we are not giving HYPERLINK function a expected reference follow. So we will use IFERROR function here.
=IFERROR(HYPERLINK(CallMe(ROW(),COLUMN()),””),”Country ” & ROW()-1)
Here in the IFERROR, you can pass the value you want to show to hover the mouse on. Like i am showing Country here. Once you insert this formula, you are ready to go.
How it works?
When you move your cursor on any hyperlink function, it change the mouse symbol to hand. and then when you click hyperlink, it activate the reference. but in this case, we are calling a UDF, so whenever you mouse mouse it will instantly call that function. In that function we are changing a cell value. Based on that cell value we can use dynamic function to change data or anything you want.
You can download the working file from link below –Mouse-Hover-Event-In-Excel.xlsm (126 downloads)
Have you started learning python yet? follow the blog and WhatsApp group to improve your python skills