Change color of cell when moving mouse over it

Delton

Board Regular
Joined
Oct 19, 2002
Messages
66
Hello,
The Excell Board "Topic" column changes color as you hover over it without selecting it. Is this an Excel/VB code? I have read about similar events here before, but the last one I tried required actually selecting a cell. If this has been previously discussed, does anyone recall the topic name. Thanks, Delton.
 
Ha ha "class action collateral frenzy". Nice try. The spirit (pun intended) of my SF beer & sourdough bread offer is business before pleasure, or in this case, code before beers & bread.

Now that I've dug myself a hole, I don't want to violate any netiquette standards with my shameless offer, but the price of a few 12-packs would be worth it to me, and a cool feature to add into the Excel community for all of us, if what Jafaar wants can really be done. If any group can do it, the people on this board can.

To clarify: What Jafaar wants (and what I would love to see) is code that causes any and every naked worksheet cell (not just cell A1) to change color by the act of gliding or hovering the mouse over such cell, without selecting any cell. "Naked cell" means, nothing in or placed on top of or attached to the cell. "Any and every" means, no matter what cell among the 16,777,216 worksheet cells you choose, this magical code will work for any one of them.

To anyone over the age of 21 who contributes on this thread towards code (that's "towards code" mind you, not just a non-contributory post that says "You're Welcome") that truly does what Jafaar is asking, I will be pleased to send a 12-pack of Anchor Steam Beer, 4 large loaves (2 sweet and 2 sour) of SF sourdough bread, and genuine Ghirardelli chocolate (sort of a San Francisco smorgasbord) that I'll personally pick up at Fisherman's Wharf and ship free of charge, wherever in the world you are. And because Delton is the Original Poster, he'll get the same package regardless.

Call it a bribe, call it shameless, call it whatever...this'd be totally cool if we can pull it off. I hope this thread does not offend anyone who is anti-alcohol, anti-bread, or anti-chocolate (your views are totally respected). I know this site has a "challenge of the month" section, but this truly is a spontaneous (and not habitual or I'd go broke) reaction to have some fun on this thread while hopefully finding a solution to a seemingly impossible task that would be a really cool feature for everyone. Thanks !!
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi Guys

Can't claim your prize Tom, but I have been playing with some of this code and come up with this that lets you draw a picture with your cursor (sort of).
Might be fun for kids.

It has two event macros and one standard macro. Before pasting the code, set up the worksheet so that cells A1:CP60 are sized to fill the screen, color the cells black (and hide column A ...to hide flicker in A1).
Drawing is initiated by right mouse click. Stop it by pressing the keyboard space bar. Clear it by selecting any cell.

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
If Target.Address = "$A$1" Then Exit Sub
Set Rng = Range("A1:CP60")
Rng.FormatConditions.Delete
Application.Run "Test"
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
[a1].Select
Set Rng = Range("A1:CP60")
Rng.FormatConditions.Delete
End Sub

Declare Function GetAsyncKeyState Lib "User32.dll" (ByVal vKey As Integer) As Long
Const VK_SPACE As Long = &H20
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Option Base 1
Public Type POINTAPI
x As Long
y As Long
End Type

Dim RwsTop()
Dim ClmnsLeft()
Dim lngCurPos As POINTAPI
Dim Rng As Range
Sub Test()

On Error Resume Next

Set Rng = Range("A1:CP60")

ReDim RwsTop(1 To Rng.Rows.Count, 2)
ReDim ClmnsLeft(1 To Rng.Columns.Count, 2)
i = 1

For Each Rw In Rng.Rows
RwsTop(i, 1) = ActiveWindow.PointsToScreenPixelsY(Rw.Top)
RwsTop(i, 2) = Rw.Row
i = i + 1
Next

i = 1
For Each Clmn In Rng.Columns
ClmnsLeft(i, 1) = ActiveWindow.PointsToScreenPixelsX(Clmn.Left)
ClmnsLeft(i, 2) = Clmn.Column
i = i + 1
Next

Do
If GetAsyncKeyState(&H20) Then GoTo errorhandler
Application.ScreenUpdating = False
GetCursorPos lngCurPos
Column = Application.WorksheetFunction.VLookup(lngCurPos.x, ClmnsLeft, 2, True)
Row = Application.WorksheetFunction.VLookup(lngCurPos.y, RwsTop, 2, True)
Cells(1, 1) = Cells(Row, Column).Address
DoEvents
If Cells(1, 1).Address <> Cells(Row, Column).Address Then GoTo here
Rng.FormatConditions.Delete
here:
Range(Cells(1, 1)).FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
Range(Cells(1, 1)).FormatConditions(1).Interior.ColorIndex = Int((56 * rnd) + 1) 'Range(Cells(1, 1)).Row + Range(Cells(1, 1)).Column
Application.ScreenUpdating = True
Loop
errorhandler:
[a1].Select
End Sub

have fun
Derek
 
Upvote 0
Thank you!

Hi,

I'm trying to find a method to highlight a range on Mouse Hover...

I would like to have an option that when I mouse over any row from it will highlight that entire row.

So...
If I mouse over either B2, C2, D2,... It will Highlight only B2, C2 and D2.
If I mouse over either B3, C3, D3,... It will Highlight only B3, C3 and D3.
etc.
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,820
Members
449,469
Latest member
Kingwi11y

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