Hi Ivan.
Doug. Run StartTimer or download the example and click on Start.
Here's an improvement using a boolean flag instead of two object references. It only changes the format when your mouse enters and exits the range. It also resets the format if your mouse moves over an area that is not a range. Download the example.
Erdinç. In my first reply I asked if you would need the ability to edit the target cell. If not, there is a lower cost way to do this.
MouseOverRange.zip
<table width="100%" border="1" bgcolor="White" style="filter
rogid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"><tr><TD><font size="2" face=Courier New> <font color="#0000A0">Option</font> <font color="#0000A0">Explicit</font>
<font color="#008000">'//</font>
<font color="#008000">'// Cursor pos orig by rafaaj2000</font>
<font color="#008000">'// Addressof routines found here;</font>
<font color="#008000">'// http://www.xcelfiles.com/API_09.html</font>
<font color="#008000">'// http://www.xcelfiles.com/VBA_Clock.html</font>
<font color="#008000">'// Timer routines;</font>
<font color="#008000">'// http://www.xcelfiles.com/API_02.html</font>
<font color="#008000">'//</font>
<font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> SetTimer _
<font color="#0000A0">Lib</font> "user32" ( _
<font color="#0000A0">ByVal</font> hWnd <font color="#0000A0">As</font> Long, _
<font color="#0000A0">ByVal</font> nIDEvent <font color="#0000A0">As</font> Long, _
<font color="#0000A0">ByVal</font> uElapse <font color="#0000A0">As</font> Long, _
<font color="#0000A0">ByVal</font> lpTimerFunc <font color="#0000A0">As</font> Long) _
<font color="#0000A0">As</font> <font color="#0000A0">Long</font>
<font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> KillTimer _
<font color="#0000A0">Lib</font> "user32" ( _
<font color="#0000A0">ByVal</font> hWnd <font color="#0000A0">As</font> Long, _
<font color="#0000A0">ByVal</font> nIDEvent <font color="#0000A0">As</font> Long) _
<font color="#0000A0">As</font> <font color="#0000A0">Long</font>
<font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetCursorPos _
<font color="#0000A0">Lib</font> "user32" ( _
lpPoint <font color="#0000A0">As</font> POINTAPI) _
<font color="#0000A0">As</font> <font color="#0000A0">Long</font>
<font color="#0000A0">Type</font> POINTAPI
x <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
Y <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
<font color="#0000A0">End</font> <font color="#0000A0">Type</font>
<font color="#0000A0">Dim</font> m_blnTimerOn <font color="#0000A0">As</font> <font color="#0000A0">Boolean</font>
<font color="#0000A0">Dim</font> m_lngTimerId <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
<font color="#0000A0">Sub</font> StartTimer()
<font color="#0000A0">If</font> <font color="#0000A0">Not</font> m_blnTimerOn <font color="#0000A0">Then</font>
m_lngTimerId = SetTimer(0, 0, 3, <font color="#0000A0">AddressOf</font> TimerProc)
m_blnTimerOn = <font color="#0000A0">True</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
<font color="#0000A0">Public</font> <font color="#0000A0">Function</font> TimerProc(ByVal hWnd <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> uMsg <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> wParam <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> lParam <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
<font color="#0000A0">Dim</font> lngCurPos <font color="#0000A0">As</font> POINTAPI
<font color="#0000A0">Dim</font> HoverRange <font color="#0000A0">As</font> Range
<font color="#0000A0">Static</font> AmHovering <font color="#0000A0">As</font> <font color="#0000A0">Boolean</font>
<font color="#008000"> '</font>
<font color="#0000A0">On</font> <font color="#0000A0">Error</font> <font color="#0000A0">Resume</font> <font color="#0000A0">Next</font>
GetCursorPos lngCurPos
<font color="#0000A0">Set</font> HoverRange = ActiveWindow.RangeFromPoint(lngCurPos.x, lngCurPos.Y)
<font color="#0000A0">If</font> HoverRange <font color="#0000A0">Is</font> <font color="#0000A0">Nothing</font> <font color="#0000A0">Then</font>
<font color="#0000A0">If</font> AmHovering <font color="#0000A0">Then</font>
AmHovering = <font color="#0000A0">False</font>
<font color="#0000A0">With</font> Range("A1")
.Value = "Mouse <font color="#0000A0">Not</font> Over"
.Font.Size = 10
.Font.ColorIndex = 0
<font color="#0000A0">End</font> <font color="#0000A0">With</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">Exit</font> <font color="#0000A0">Function</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">If</font> HoverRange.Address = "$A$1" <font color="#0000A0">Then</font>
<font color="#0000A0">If</font> <font color="#0000A0">Not</font> AmHovering <font color="#0000A0">Then</font>
AmHovering = <font color="#0000A0">True</font>
<font color="#0000A0">With</font> Range("A1")
.Value = "Mouse Over"
.Font.Size = 14
.Font.ColorIndex = 3
<font color="#0000A0">End</font> <font color="#0000A0">With</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">Else</font>
<font color="#0000A0">If</font> AmHovering <font color="#0000A0">Then</font>
AmHovering = <font color="#0000A0">False</font>
<font color="#0000A0">With</font> Range("A1")
.Value = "Mouse <font color="#0000A0">Not</font> Over"
.Font.Size = 10
.Font.ColorIndex = 0
<font color="#0000A0">End</font> <font color="#0000A0">With</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">End</font> <font color="#0000A0">Function</font>
<font color="#0000A0">Sub</font> StopTimer()
<font color="#0000A0">If</font> m_blnTimerOn <font color="#0000A0">Then</font>
KillTimer 0, m_lngTimerId
m_blnTimerOn = <font color="#0000A0">False</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table><button onclick='document.all("101200691643843").value=document.all("101200691643843").value.replace(/<br \/>\s\s/g,"");document.all("101200691643843").value=document.all("101200691643843").value.replace(/<br \/>/g,"");window.clipboardData.setData("Text",document.all("101200691643843").value);'>Copy to Clipboard</BUTTON><textarea style="position:absolute;visibility:hidden" name="101200691643843" wrap="virtual">
Option Explicit
'//
'// Cursor pos orig by rafaaj2000
'// Addressof routines found here;
'//
http://www.xcelfiles.com/API_09.html
'//
http://www.xcelfiles.com/VBA_Clock.html
'// Timer routines;
'//
http://www.xcelfiles.com/API_02.html
'//
Declare Function SetTimer _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) _
As Long
Declare Function KillTimer _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long) _
As Long
Declare Function GetCursorPos _
Lib "user32" ( _
lpPoint As POINTAPI) _
As Long
Type POINTAPI
x As Long
Y As Long
End Type
Dim m_blnTimerOn As Boolean
Dim m_lngTimerId As Long
Sub StartTimer()
If Not m_blnTimerOn Then
m_lngTimerId = SetTimer(0, 0, 3, AddressOf TimerProc)
m_blnTimerOn = True
End If
End Sub
Public Function TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lngCurPos As POINTAPI
Dim HoverRange As Range
Static AmHovering As Boolean
'
On Error Resume Next
GetCursorPos lngCurPos
Set HoverRange = ActiveWindow.RangeFromPoint(lngCurPos.x, lngCurPos.Y)
If HoverRange Is Nothing Then
If AmHovering Then
AmHovering = False
With Range("A1")
.Value = "Mouse Not Over"
.Font.Size = 10
.Font.ColorIndex = 0
End With
End If
Exit Function
End If
If HoverRange.Address = "$A$1" Then
If Not AmHovering Then
AmHovering = True
With Range("A1")
.Value = "Mouse Over"
.Font.Size = 14
.Font.ColorIndex = 3
End With
End If
Else
If AmHovering Then
AmHovering = False
With Range("A1")
.Value = "Mouse Not Over"
.Font.Size = 10
.Font.ColorIndex = 0
End With
End If
End If
End Function
Sub StopTimer()
If m_blnTimerOn Then
KillTimer 0, m_lngTimerId
m_blnTimerOn = False
End If
End Sub</textarea>
MouseOverRange.zip