Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard Shortcut - Highlight the Current Row in Excel
#1
Lightbulb 
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!
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.
Enterpad: For those who need more than a few shortcuts.

Reply
#2
If you want to insert a new sheet into the book, use this key combination Shift + F11. When you enter this shortcut, the new sheet is inserted into the current book. To add additional sheets, press and hold the Shift key, press F11 and release both keys. If you want to sum data in rows and columns, use the key combination to insert the Excel SUM function into your worksheet. Key combination to enter the SUM function: Alt + = (equal sign). This is how the keyboard shortcut will be adapted. Or easier - see https://blog.coupler.io/data-transformation-techniques/ adapt keyboard values.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)