Access the ThisWorkbook module 1. Access the ThisWorkbook module In Excel, press Alt + F11 to open the VBA editor. In the left pane, locate the object named ThisWorkbook (it's under "Microsoft Excel Objects"). Double-click it to open its code window. This module allows you to execute code that applies to the entire workbook, regardless of the active sheet. 2. Insert the global code Paste the following code into the ThisWorkbook window: vba Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Sh.Cells.Interior.ColorIndex = xlNone Sh.Rows(Target.Row).Interior.Color = RGB(220, 230, 241) End Sub This code uses the Workbook_SheetSelectionChange event, which is triggered whenever you select a cell in any sheet of the workbook. It automatically applies the color to the corresponding row. 3. Enable macros and test Close the VBA editor (Alt + Q), then make sure that macros are enabled in Excel (File > Options > Trust Center > Macro Settings). Then, test by clicking on different cells in several sheets: the active row should change color each time. And there you have it, your entire workbook is now interactive and much more readable!
No comments yet