Is VisualBasic able to code for highlighting a row when mouse cursor is hovering over that row?
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
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, 1 month 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
-
Microsoft Bing Video Creator
by
Alex5723
44 minutes ago -
Firefox Red Panda Fun Stuff
by
Lars220
3 hours, 53 minutes ago -
How start headers and page numbers on page 3?
by
Davidhs
7 hours, 25 minutes ago -
Attack on LexisNexis Risk Solutions exposes data on 300k +
by
Nibbled To Death By Ducks
2 hours, 1 minute ago -
Windows 11 Insider Preview build 26200.5622 released to DEV
by
joep517
16 hours, 6 minutes ago -
Windows 11 Insider Preview build 26120.4230 (24H2) released to BETA
by
joep517
16 hours, 8 minutes ago -
MS Excel 2019 Now Prompts to Back Up With OneDrive
by
lmacri
5 hours, 49 minutes ago -
Firefox 139
by
Charlie
18 hours, 31 minutes ago -
Who knows what?
by
Will Fastie
11 hours, 13 minutes ago -
My top ten underappreciated features in Office
by
Peter Deegan
16 hours, 52 minutes ago -
WAU Manager — It’s your computer, you are in charge!
by
Deanna McElveen
11 hours, 15 minutes ago -
Misbehaving devices
by
Susan Bradley
19 hours ago -
.NET 8.0 Desktop Runtime (v8.0.16) – Windows x86 Installer
by
WSmeyerbos
1 day, 22 hours ago -
Neowin poll : What do you plan to do on Windows 10 EOS
by
Alex5723
1 hour, 13 minutes ago -
May 31, 2025—KB5062170 (OS Builds 22621.5415 and 22631.5415 Out-of-band
by
Alex5723
1 day, 21 hours ago -
Discover the Best AI Tools for Everything
by
Alex5723
20 hours, 34 minutes ago -
Edge Seems To Be Gaining Weight
by
bbearren
1 day, 11 hours ago -
Rufus is available from the MSFT Store
by
PL1
1 day, 19 hours ago -
Microsoft : Ending USB-C® Port Confusion
by
Alex5723
2 days, 22 hours ago -
KB5061768 update for Intel vPro processor
by
drmark
22 hours, 21 minutes ago -
Outlook 365 classic has exhausted all shared resources
by
drmark
21 hours, 4 minutes ago -
My Simple Word 2010 Macro Is Not Working
by
mbennett555
2 days, 18 hours ago -
Office gets current release
by
Susan Bradley
2 days, 20 hours ago -
FBI: Still Using One of These Old Routers? It’s Vulnerable to Hackers
by
Alex5723
4 days, 10 hours ago -
Windows AI Local Only no NPU required!
by
RetiredGeek
3 days, 19 hours ago -
Stop the OneDrive defaults
by
CWBillow
4 days, 11 hours ago -
Windows 11 Insider Preview build 27868 released to Canary
by
joep517
4 days, 21 hours ago -
X Suspends Encrypted DMs
by
Alex5723
4 days, 23 hours ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
5 days ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
5 days ago
Recent blog posts
Key Links
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
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.