Is VisualBasic able to code for highlighting a row when mouse cursor is hovering over that row?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
code to highlight Excel row upon hover
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » code to highlight Excel row upon hover
- This topic has 23 replies, 7 voices, and was last updated 10 years ago.
AuthorTopicWScalvin2a
AskWoody LoungerApril 25, 2015 at 3:45 pm #499672Viewing 14 reply threadsAuthorReplies-
RetiredGeek
AskWoody_MVPApril 25, 2015 at 3:59 pm #1501800Calvin,
I can’t find an event to accomplish that in either the Workbook or Sheet models. HTH :cheers:
-
Maudibe
AskWoody_MVPApril 25, 2015 at 6:50 pm #1501824RG,
I am sure you can do something with the code here to make it work
http://windowssecrets.com/forums/showthread//165438-Instructions-for-textboxes
Maud
-
RetiredGeek
AskWoody_MVPApril 25, 2015 at 9:41 pm #1501838Maud,
Nice piece of code but unfortunately the Mouse events are Methods of the Textbox class short of putting a textbox at the top of each column I don’t see how to use it to accomplish the OP’s task. Am I missing something? :cheers:
-
Maudibe
AskWoody_MVPApril 26, 2015 at 9:51 am #1501891“With a little help from my friends” Beatles, Sgt. Pepper’s Lonely Hearts Club Band, June, 1967
As RG pointed out, a mouseover for a textbox has no practical application in Calvin’s needs. I initially was working with a hyperlink formula to point to the macro but that would mean that every cell in the range would need to have the formula inserted making that an impractical approach as well. So I turned to x-y coordinates and am almost there.
I need some input from you (all members) to get around an obstacle I am running into to highlight the rows when hovered over. The following code will highlight the rows moving the mouse over the cells for about 5 seconds but then stops highlighting even though the code is still running in the background. To end the code, just move the cursor outside the range of data.
If someone can come up with a workaround to get pass the 5 second time limit, they will get a well deserved press on their “Thanks” button from me (best I can offer).
Maud
This code was adapted from Any Pope’s code to find the xy coordinates over at Ozgrid
Code:Declare Function GetCursorPos Lib “user32” (lpPoint As POINTAPI) As Long Type POINTAPI x As Long y As Long End Type Sub CurosrXY_Pixels() Dim lngStatus As Long Dim typWhere As POINTAPI Dim rng As Range Set rng = Range(“A1:E19”) Range(“H3”) = 0 Range(“I3”) = 0 Do While Range(“H3”) <= 357 And Range("I3") <= 566 lngStatus = GetCursorPos(typWhere) Range("H3") = typWhere.x Range("I3") = typWhere.y Row = Int(Range("I3") / 20) – 8 Range("G3") = Row rng.Interior.Color = vbWhite Range("A" & Row & ":E" & Row).Interior.Color = vbRed Loop End Sub
-
RetiredGeek
AskWoody_MVPApril 26, 2015 at 10:31 am #1501901Maud,
I can’t seem to get the code to do anything except on occasion flip between rows 3 & 4. It seems to me you’d need a loop to almost continuously monitor the cursor position. :cheers:
-
Maudibe
AskWoody_MVPApril 26, 2015 at 10:48 am #1501903RG,
There is a loop in the code. Strange that I can go up and down the entire range and the highlighting of the rows will follow for about 5 seconds. Are you keeping your cursor with in the data range? I am wondering if resolution comes into play here. Try staying closer to column A when sliding the cursor up and down or expanding the pixel ranges in Do While Range(“H3”) <= 357 And Range("I3") <= 566. Or are you timing out less than 5 seconds?
Here is a video of what it looks like, however, the cursor does not get recorded. After about 5 seconds, it stops highlighting and I move the cursor out of range to end the code. The Start button returns to normal state
-
RetiredGeek
AskWoody_MVPApril 26, 2015 at 11:29 am #1501909Maud,
The start button reverts to normal immediately on my Desktop Haswell i-7! However, I copied it over to my Laptop an older Allendale i-5 and it works as shown in your video across the whole range of table cells FOR ABOUT 2 MINUTES!.
I did a second test after widening all the table cells and it quit as soon as I moved out of the predefined size but still within the table.
Third test where I just zoomed the screen with the same results as the 2nd test.
Doesn’t look like it will be a reliable method since it is obviously dependent on processor speed, screen resolution, and cell width. HTH :cheers:
-
Maudibe
AskWoody_MVPApril 26, 2015 at 11:48 am #1501912RG,
Thanks for the follow-up. I too have a core I7 but first generation oc to 4.2GHz. Maybe not as fast as yours. Using your “beast rig”, could you try doubling the x-y-pixels in the line Do While Range(“H3”) <= 357 And Range("I3") <= 566 while keeping the cell width at 8.43(64 pixels) and the cell height at 15.0(20 pixels). My resolution is at 1960 x 1080. What is yours? Any thoughts on the timeout issue? contemplating a pause function.
Update: adding the pause seemed to cure the time out. but still need to work on resolution issue. RG- I await your test results when you get around to it
Code:Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Type POINTAPI x As Long y As Long End Type Sub CurosrXY_Pixels() Dim lngStatus As Long Dim typWhere As POINTAPI Dim rng As Range Set rng = Range("A1:E19") Range("H3") = 0 Range("I3") = 0 Do While Range("H3") <= 357 And Range("I3") <= 566 lngStatus = GetCursorPos(typWhere) Range("H3") = typWhere.x Range("I3") = typWhere.y Row = Int(Range("I3") / 20) – 8 Range("G3") = Row rng.Interior.Color = vbWhite Range("A" & Row & ":E" & Row).Interior.Color = vbRed [COLOR="#0000FF"] Pause[/COLOR] Loop End Sub Private Sub Pause() [COLOR="#008000"]'—————————————- 'CHANGE PAUSETIME TO ADJUST SPEED[/COLOR] Dim PauseTime, Start PauseTime = 0.05 Start = Timer Do While Timer < Start + PauseTime DoEvents Loop End Sub
-
RetiredGeek
AskWoody_MVPApril 26, 2015 at 12:52 pm #1501916Maud,
Set up as you instructed…No change!
My screen resolution is 1920X1080. HTH :cheers:
-
zeddy
AskWoody_MVP -
WSSupershoe
AskWoody LoungerApril 29, 2015 at 8:42 am #150233340417-rz-mouse-position-v2 You may like this as well or better. See Attached
Code:Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Range) Cells.FormatConditions.Delete If ActiveSheet.Shapes("Check Box 1").ControlFormat.Value = 1 Then With Target.EntireRow .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE" .FormatConditions(1).Interior.ColorIndex = 35 End With End If End Sub
-
zeddy
AskWoody_MVP
-
-
-
-
RetiredGeek
AskWoody_MVPApril 26, 2015 at 3:26 pm #1501932Zeddy,
Nice job! :thewave:
Also a nice explanation despite the MS “confuse the user” speak!
Would have been even nicer if you’d mentioned the Conditional Formatting! I spent a lot of time trying to figure out where the color was set in the code. :confused: Of course I could have missed it in the MS speak.
Almost forgot it’s easy to modify to do Columns vs Rows.
:cheers:
-
zeddy
AskWoody_MVP -
zeddy
AskWoody_MVP -
RetiredGeek
AskWoody_MVPApril 26, 2015 at 4:42 pm #1501946Hi RG
..I re-checked my posted file.
Did you see that note in cell [C9]zeddy
Zeddy,
Nope! Must have been too dazzled by the flashing Yellow lights!
35623-ROTFLOLSorry about that! :cheers:
-
zeddy
AskWoody_MVP
-
-
-
-
-
Maudibe
AskWoody_MVP -
Maudibe
AskWoody_MVP -
access-mdb
AskWoody MVP -
zeddy
AskWoody_MVP
-
-
WSfburg
AskWoody Lounger -
Maudibe
AskWoody_MVP
Viewing 14 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Sometimes I wonder about these bots
by
Susan Bradley
2 hours, 56 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
4 hours, 54 minutes ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
5 hours, 54 minutes ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
5 hours, 19 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
1 hour, 49 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
8 hours, 36 minutes ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
8 hours, 37 minutes ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
2 hours, 30 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
16 hours, 45 minutes ago -
0Patch, where to begin
by
cassel23
10 hours, 47 minutes ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
1 day, 6 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
18 hours, 8 minutes ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
1 day, 14 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
1 day, 5 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
17 hours, 2 minutes ago -
Installer program can’t read my registry
by
Peobody
6 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
1 day, 3 hours ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
1 day, 11 hours ago -
False error message from eMClient
by
WSSebastian42
2 days, 2 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
2 days, 11 hours ago -
Office 2021 Perpetual for Mac
by
rebop2020
2 days, 12 hours ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
1 day, 8 hours ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
2 days, 15 hours ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
1 day, 16 hours ago -
Outdated Laptop
by
jdamkeene
2 days, 21 hours ago -
Updating Keepass2Android
by
CBFPD-Chief115
3 days, 2 hours ago -
Another big Microsoft layoff
by
Charlie
3 days, 2 hours ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
4 hours, 31 minutes ago -
May 2025 updates are out
by
Susan Bradley
6 hours, 13 minutes ago -
Windows 11 Insider Preview build 26200.5600 released to DEV
by
joep517
3 days, 8 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.