VB 51
Excel Highlight Row VBA By mike on 28th March 2021 03:46:54 PM
  1. https://www.thesmallman.com/blog/2016/9/15/auto-highlight-the-active-row-when-a-cell-is-selected
  4. Highlighting rows with conditional formatting in itself is not difficult. It is the automatic part that is tricky.
  6. First, select all continuous data by selecting a cell in your data and using the shortcut ‘Ctrl + A’. In the project file, the selected range is A1:E55.
  8. Then, click the ‘Conditional Formatting’-button on the ‘Home’ tab in the ribbon.
  10. Click ‘New Rule’ and in the following dialog box choose ‘Use a formula to determine which cells to format’.
  12. In the formula field, enter this formula:
  14. =OR(CELL("row")=CELL("row",A1))
  16. The last argument of the second ‘CELL’-function (the A1) must be the top left cell of the selected data (from before you clicked the ‘Conditional Formatting’ button).
  19. Writing The Macro
  20. I have written the macro for you, but it is not complicated. It simply looks like this:
  22. Option Explicit
  24. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  25.    Target.Calculate
  26. End Sub
  28. This code goes not in a normal module, but in the code belonging to a specific worksheet. Use the shortcut ‘Alt + F11’ to get to the ‘VBA editor’.
  30. Double click ‘Sheet2(Employees)’ in the ‘Project Explorer’ and paste the code from above. If your ‘Project Explorer’ (the menu to the left) is missing and it does not look like the screenshot on your computer, you need to toggle on the ‘Project Explorer’. Click ‘View’ in the menu and click ‘Project Explorer’.

Hasta la pasta! is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.