Forum Discussion

GregV999's avatar
GregV999
Copper Contributor
Jan 27, 2021

hovering with cursor

How do i get the cursor to display which cell I am touching when I hover over it?

1 Reply

  • JMB17's avatar
    JMB17
    Bronze Contributor

    GregV999 

     

    I think you will need vba to do that. I've never done it myself, but I think this may get you started:

     

    Option Explicit
    
    Public Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Public Type POINTAPI
         x As Long
         y As Long
    End Type
    
    Sub TrackCursor()
         Dim mousePos As POINTAPI
         Dim curCell As Range
         Dim target As Range
         
         On Error Resume Next
         
         '//  Change where/how to display it as needed.
         Set target = Sheet1.Range("A1")
         
         Do
              GetCursorPos mousePos
              Set curCell = GetRangeFromXY(mousePos.x, mousePos.y)
              target.Value = curCell.Address
              DoEvents
              
              '//  You may set up a check here for some trigger
              '//  (maybe a cell that is TRUE/FALSE) to break
              '//  out of the loop and exit the procedure.
              
         Loop
    End Sub
    
    Function GetRangeFromXY(x As Long, y As Long) As Range
        On Error Resume Next
        Set GetRangeFromXY = ActiveWindow.RangeFromPoint(x, y)
    End Function

     

     

Resources