A keyboard shortcut to quickly highlight a row in Excel (change its background color to yellow, for instance) will certainly be appreciated by someone having to analyze plenty of data. The following AutoHotkey script allows you to do exactly this. Also, if the row is already highlighted, the same keyboard shortcut will simply remove the highlight. This shortcut works with any worksheet; no Excel add-in required.
Need help creating a keyboard shortcut with ShortKeeper using the following AutoHotkey code? This 5-minute tutorial will help!
The script will highlight the row (or remove the highlight) if the Excel worksheet is the active window and is not busy (e.g. editing, selecting a command).
The number 6 in line #2 sets the color of the highlight to yellow. A decimal number from 0 to 56 allows for different color options. The following list includes some common color choices:
This script is optimized to be used with ShortKeeper. As such, there is no exception handling, no “Return” at the end, and variable(s) don’t need to be cleared. ShortKeeper does all of this automatically. Just copy/paste the code in the PARAM field in ShortKeeper, set your hotkey, save, and you’re ready to use your new keyboard shortcut.
Need help creating a keyboard shortcut with ShortKeeper using the following AutoHotkey code? This 5-minute tutorial will help!
Critical
HCIndex := 6
if WinActive("ahk_class XLMAIN")
{
ControlGet, hwnd, hwnd, , Excel71, A
if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hwnd, "UInt", 0xFFFFFFF0, "Ptr", -VarSetCapacity(IID,16)+NumPut(0x46000000000000C0, NumPut(132096, IID, "Int64"), "Int64"), "Ptr*", pacc) = 0
ExcelApp := ComObject(9, pacc, 1).Application
Row := ExcelApp.Rows(ExcelApp.Selection.Row).Interior
if Row.ColorIndex = HCIndex
Row.ColorIndex := 0
else
Row.ColorIndex := HCIndex
}
else
MsgBox 0x40040, ShortKeeper, There is no Excel worksheet window active.
The script will highlight the row (or remove the highlight) if the Excel worksheet is the active window and is not busy (e.g. editing, selecting a command).
The number 6 in line #2 sets the color of the highlight to yellow. A decimal number from 0 to 56 allows for different color options. The following list includes some common color choices:
- Auto, 0
- Black, 1
- White, 2
- Red, 3
- Bright Green, 4
- Blue, 5
- Yellow, 6
- Pink, 7
- Turquoise, 8
- Dark Red, 9
- Green, 10
- Dark Blue, 11
- Dark Yellow, 12
- Violet, 13
- Teal, 14
- Grey 25, 15
- Grey 50, 16
This script is optimized to be used with ShortKeeper. As such, there is no exception handling, no “Return” at the end, and variable(s) don’t need to be cleared. ShortKeeper does all of this automatically. Just copy/paste the code in the PARAM field in ShortKeeper, set your hotkey, save, and you’re ready to use your new keyboard shortcut.