Tom Urtis__Pls have a look here.

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,806
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I used the rather overlooked property ( RangeFromPoint) to find a solution to the problem :(Highlighting cell under mouse pointer)raised here : http://www.mrexcel.com/board2/viewtopic.php?t=90381&highlight=mouse

...Can't believe I missed this handy property which makes the whole thing so easy.

I have tried the code below and it worked quite nicely for me apart from the mouse flickering which I hope I could get rid of.

Code:
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Public Type POINTAPI
    x As Long
    y As Long
End Type

Dim lngCurPos As POINTAPI
Dim Cancel As Boolean
Dim R As Range
Dim oldColor As Long

Public Sub ChangeCellColor()
    Cancel = False
    On Error Resume Next
        Do Until Cancel = True
            With ActiveWindow
                If Not R Is .RangeFromPoint(lngCurPos.x, lngCurPos.y) Then
                    R.Interior.ColorIndex = oldColor
                End If
                GetCursorPos lngCurPos
                Set R = .RangeFromPoint(lngCurPos.x, lngCurPos.y)
                oldColor = R.Interior.ColorIndex
                .RangeFromPoint(lngCurPos.x, lngCurPos.y).Interior.ColorIndex = 3 'Red
            End With
        DoEvents
        Loop
End Sub

Public Sub CancelProcedure()
    Cancel = True
    Set R = Nothing
End Sub


Hey Tom, is the Beers prize still on ? :lol:

Regards.
 
rafaaj2000 said:
I hate the title I gave this thread..It sounds so sloppy
Well call me biased, but personally I think the title has a nice ring to it.

Thanks for the improved code Jaafar, I've updated my notes with your modification.
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top