Using VBA to highlight the active row in Excel lets you instantly see which row your cursor is in, even across wide spreadsheets. This is especially useful for data entry, auditing, or navigating large datasets. No add-ins or external tools are required—just the built-in VBA editor in Excel. The code runs automatically when you select a new cell, updating the highlight in real time.

What You'll Need

  • Microsoft Excel (2010 or later, Windows or Mac)
  • Enablement of Developer tab in Excel (if not already visible)
  • Permission to run macros in your workbook (set to "Enable Macros" when prompted)

Step-by-Step

  1. Open the Excel workbook where you want to highlight the active row. Save it as a macro-enabled file (.xlsm) if it isn’t already—this is required to keep the VBA code saved.
  2. Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
  3. In the Project Explorer window on the left, find your workbook’s name (e.g., "VBAProject (YourWorkbookName.xlsm)"). Double-click on "ThisWorkbook" under your workbook name to open its code window.
  4. Copy and paste the following code into the code window:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Dim ws As Worksheet
    Set ws = Sh
    
    ' Clear previous highlights
    ws.Rows.Interior.ColorIndex = xlNone
    
    ' Highlight the entire row of the selected cell
    ws.Rows(Target.Row).Interior.Color = RGB(200, 230, 255)
End Sub
  1. Close the VBA editor by clicking the X or pressing Alt + Q.
  2. Return to your Excel worksheet. Click any cell. The entire row of that cell should now be highlighted in a light blue color.
  3. Test by moving your selection to another row. The previous row’s highlight disappears, and the new row is highlighted automatically.

Common Mistakes

  • Not saving the file as .xlsm—this causes the VBA code to be lost when you close the workbook.
  • Pasting the code into a regular module (like Module1) instead of "ThisWorkbook"—the code must be in the ThisWorkbook object to respond to selection changes across all sheets.
  • Using a color that blends with your data—for example, white or light gray—making the highlight invisible. Always use a color that contrasts with your cell backgrounds.
  • Assuming the highlight will work on protected sheets—the code will fail if the sheet is protected without allowing cell selection. Unprotect the sheet or allow "Select unlocked cells" in the protection settings.
  • Trying to use the code in Excel Online or mobile apps—VBA is not supported in these versions. It only works in desktop Excel.

Tips

  • To change the highlight color, edit the RGB values in the code: RGB(200, 230, 255) is light blue. Try RGB(255, 255, 153) for pale yellow, or RGB(221, 235, 211) for soft green.
  • If you want to highlight only specific sheets, wrap the code in an If statement: If ws.Name = "Data" Then before the highlighting lines.
  • To highlight both the row and column, add ws.Columns(Target.Column).Interior.Color = RGB(200, 230, 255) after the row line.
  • Use ws.Rows(Target.Row).Interior.ColorIndex = 35 instead of RGB if you prefer a standard color index—color index 35 is a light blue, matching the default highlight.
  • For better performance on very large sheets, add Application.ScreenUpdating = False at the start and Application.ScreenUpdating = True at the end of the code to prevent flickering.

Troubleshooting

  • The row doesn’t highlight at all. Check if macros are enabled. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and ensure "Enable all macros" or "Disable all macros with notification" is selected. When you open the file, click "Enable Content" if prompted.
  • The highlight appears but disappears when I scroll. This is normal—the highlight updates only when the selection changes, not during scrolling. The row remains highlighted as long as that cell is selected, even if it scrolls out of view.
  • I get a runtime error. This usually means the sheet is protected. Go to Review > Unprotect Sheet. If you don’t know the password, you cannot use this code on that sheet without removing protection.
  • The code works on one sheet but not another. The code is designed to work on all sheets. If it doesn’t, check that you pasted the code into "ThisWorkbook" and not into a specific sheet’s module. If you pasted it into Sheet1, it will only work on Sheet1.
  • Excel freezes or lags when I select cells. This happens on sheets with thousands of rows. Add Application.Calculation = xlCalculationManual at the start and Application.Calculation = xlCalculationAutomatic at the end to reduce processing load.

Frequently Asked Questions

Can I highlight the active row in Excel Online?

No, Excel Online does not support VBA. This feature only works in desktop versions of Excel for Windows or Mac.

Will this work if I have multiple monitors or split windows?

Yes. The code works regardless of window layout or monitor setup. It highlights the row based on the active cell’s position in the worksheet, not its visual location on screen.

Can I make the highlight persist after I move off the row?

No, the code is designed to highlight only the currently selected row. To keep multiple rows highlighted, you’d need to manually apply conditional formatting or write a different macro that tracks user input.

Why does the highlight disappear when I copy and paste data?

Because copying and pasting doesn’t change the active cell selection, the highlight remains. If you paste into a different row and the selection moves, the highlight will update to the new row. If the selection doesn’t move, the highlight stays.

Can I use this with conditional formatting instead of VBA?

Yes, but it’s less dynamic. Conditional formatting can highlight the active row using a formula like =CELL("row")==ROW(), but this requires the worksheet to be set to manual calculation and won’t update instantly unless you force a recalculation. VBA is faster and more reliable.

Does this work in Excel for Mac?

Yes, as long as you’re using Excel 2016 or later on macOS and have enabled macros. The VBA editor and code work identically to Windows, though the shortcut to open it is Option + ⌘ + F11.