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_MVPMaudibe
AskWoody_MVPaccess-mdb
AskWoody MVP-
zeddy
AskWoody_MVP
WSfburg
AskWoody LoungerMaudibe
AskWoody_MVPViewing 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
-
Where’s the cache today?
by
Up2you2
42 minutes ago -
Ascension says recent data breach affects over 430,000 patients
by
Nibbled To Death By Ducks
2 hours, 22 minutes ago -
Nintendo Switch 2 has a remote killing switch
by
Alex5723
2 hours, 43 minutes ago -
Blocking Search (on task bar) from going to web
by
HenryW
7 hours, 23 minutes ago -
Windows 10: Microsoft 365 Apps will be supported up to Oct. 10 2028
by
Alex5723
12 hours, 30 minutes ago -
Add or Remove “Ask Copilot” Context Menu in Windows 11 and 10
by
Alex5723
12 hours, 37 minutes ago -
regarding april update and may update
by
heybengbeng
14 hours, 6 minutes ago -
MS Passkey
by
pmruzicka
1 hour, 54 minutes ago -
Can’t make Opera my default browser
by
bmeacham
21 hours, 47 minutes ago -
*Some settings are managed by your organization
by
rlowe44
8 hours, 30 minutes ago -
Formatting of “Forward”ed e-mails
by
Scott Mills
20 hours, 41 minutes ago -
SmartSwitch PC Updates will only be supported through the MS Store Going Forward
by
PL1
1 day, 16 hours ago -
CISA warns of hackers targeting critical oil infrastructure
by
Nibbled To Death By Ducks
2 days, 1 hour ago -
AI slop
by
Susan Bradley
15 hours, 28 minutes ago -
Chrome : Using AI with Enhanced Protection mode
by
Alex5723
2 days, 2 hours ago -
Two blank icons
by
CR2
14 hours, 24 minutes ago -
Documents, Pictures, Desktop on OneDrive in Windows 11
by
ThePhoenix
2 days, 11 hours ago -
End of 10
by
Alex5723
2 days, 14 hours ago -
Single account cannot access printer’s automatic duplex functionality
by
Bruce
1 day, 12 hours ago -
test post
by
gtd12345
2 days, 20 hours ago -
Privacy and the Real ID
by
Susan Bradley
2 days, 10 hours ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
12 hours, 43 minutes ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
3 days ago -
Upgrading from Win 10
by
WSjcgc50
1 day, 12 hours ago -
USB webcam / microphone missing after KB5050009 update
by
WSlloydkuhnle
1 day, 15 hours ago -
TeleMessage, a modified Signal clone used by US government has been hacked
by
Alex5723
3 days, 16 hours ago -
The story of Windows Longhorn
by
Cybertooth
3 days, 4 hours ago -
Red x next to folder on OneDrive iPadOS
by
dmt_3904
3 days, 18 hours ago -
Are manuals extinct?
by
Susan Bradley
18 hours, 35 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
4 days, 3 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.