Highlighting the row of the currently selected cell
global lastHighlightedRow as long
sub highlightRowOfSelectedCell()
if lastHighlightedRow > 0 Then
rows(lastHighlightedRow).Interior.ColorIndex = 0 ' no fill?
end if
rows(selection.row).interior.color = rgb(230, 230, 230)
lastHighlightedRow = selection.row
end sub
Highlighting the row the mouse is hovering over
The following function (sub
) highlights the row that the mouse is currently hovering over. Additionally, it un-highlights the previously highlighted row.
In order to determine the position of the mouse, it needs the
Win API function
GetCursorPos
.
option explicit
declare function GetCursorPos Lib "user32" (lpPoint as POINTAPI) as long
type POINTAPI
x as long
Y as long
end type
global lastHighligtedRow as long
sub highlightRow
dim cursorPos as POINTAPI
GetCursorPos cursorPos
dim rng as range
set rng = activeWindow.rangeFromPoint(cursorPos.x, cursorPos.Y)
if lastHighligtedRow > 0 then
rows(lastHighligtedRow).interior.colorIndex = 0 ' no fill?
end if
rows(rng.row).interior.color = rgb(230, 230, 230)
lastHighligtedRow = rng.row
end sub
In order to add a shortcut key to call the function automatically, the following can be used:
application.onKey "{F10}", "highlightRow"