Highlight Entire Row When Cell Is Selected

How-to basics · Updated November 23, 2026

Yes, you can highlight the entire row when a cell is selected in Excel by using a combination of conditional formatting and a VBA macro. The simplest no-code method uses a conditional formatting formula with the CELL function, but it requires a macro to refresh the highlight after selection changes. For a fully automatic solution, a small VBA event macro is the standard approach.

Why Highlight the Active Row?

When working with wide spreadsheets, it is easy to lose track of which row you are entering data into. Highlighting the entire active row draws a clear visual boundary across all columns, reducing the chance of typing values into the wrong row or misreading a figure. This is especially useful in financial models, inventory lists, or any dataset with many columns where the row label is far from the cell you are editing.

Excel does not have a built-in setting that automatically highlights the active row. The feature must be created with conditional formatting or VBA. The conditional formatting approach uses the CELL function to detect the active cell, but because Excel does not recalculate conditional formatting when the selection changes, a macro is needed to force a recalculation. The VBA approach directly changes the interior color of the row whenever the selection moves.

Method 1: Conditional Formatting with CELL (Requires a Macro)

This method uses a conditional formatting rule based on the CELL function, which returns the row number of the active cell. To make it update when you move to a different cell, you must add a small VBA macro that recalculates the worksheet.

  1. Select the entire range where you want the highlight to appear (for example, A1:Z100).
  2. Go to Home > Conditional Formatting > New Rule.
  3. Choose Use a formula to determine which cells to format.
  4. Enter this formula (assuming the top-left cell of your selection is A1):
    =ROW()=CELL("row")
  5. Click Format, choose a fill color, and click OK.
  6. Press Alt+F11 to open the VBA editor.
  7. In the Project Explorer, double-click the sheet you are working on (e.g., Sheet1).
  8. Paste the following code into the code window:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    ' Force Excel to recalculate the CELL function
    Application.Calculate
End Sub

Close the editor and save the workbook as a macro-enabled file (.xlsm). Now, when you click any cell in the formatted range, the entire row will highlight. Note that the CELL function is volatile, so the macro forces a recalculation each time the selection changes.

Mac warning: Macros cannot be undone with Ctrl+Z, so always save a copy of your workbook before adding VBA code.

Method 2: VBA Event Macro (Direct Highlighting)

This method uses the Worksheet_SelectionChange event to directly change the interior color of the row. It is more efficient because it does not rely on conditional formatting recalculation.

  1. Press Alt+F11 to open the VBA editor.
  2. Double-click the target sheet in the Project Explorer.
  3. Paste the following code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    ' Clear previous highlight
    Cells.Interior.ColorIndex = xlNone
    
    ' Highlight the entire row of the active cell
    Rows(Target.Row).Interior.Color = RGB(255, 255, 0) ' Light yellow
End Sub

This clears all fills, then colors the row of the selected cell. To limit the highlight to a specific data range (e.g., A1:Z100), replace Cells.Interior.ColorIndex = xlNone with Range("A1:Z100").Interior.ColorIndex = xlNone and Rows(Target.Row).Interior.Color = ... with Range("A" & Target.Row & ":Z" & Target.Row).Interior.Color = .... This prevents clearing fills outside your data area.

Remember to save the workbook as .xlsm and keep a backup copy before running macros.

Choosing Between Conditional Formatting and VBA

Your choice depends on your needs:

  • Conditional Formatting + CELL: Keeps formatting rules visible in the Manage Rules dialog, but requires a macro to update and may be slower on very large sheets.
  • VBA Event Macro: More direct and faster, but it overwrites existing cell fills unless you code around it. It also requires macro-enabled file format.

If you need to preserve existing cell colors, the VBA macro must store and restore original colors, which is more complex. Conditional formatting does not overwrite existing fills—it only applies when the condition is true, so it is safer for sheets with pre-formatted cells.

Common Problems and Solutions

Problem 1: The highlight does not update when you move to another cell. This happens with the conditional formatting method if you do not have the macro. The macro forces a recalculation. Without it, the highlight stays on the first row you selected.

Problem 2: The VBA macro clears all fills, including ones you set manually. To avoid this, use a more advanced macro that stores the original color of each cell before highlighting. For example, you can use a module-level variable to store the previous row’s original colors, but this requires more code.

Problem 3: The highlight does not appear on cells with existing formatting. In conditional formatting, the highlight will only show if the rule’s format overrides the cell’s own format. By default, conditional formatting takes precedence, but if the cell has a theme or style, you may need to adjust the rule’s priority.

Problem 4: The macro slows down on large sheets. The VBA method clears and recolors the entire row, which can be slow if you have thousands of rows. Limit the range to your actual data area to improve performance.

Highlighting the Entire Row and Column Together

Some users want both the row and column highlighted to create a crosshair effect. You can modify the VBA macro to highlight both:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Cells.Interior.ColorIndex = xlNone
    Rows(Target.Row).Interior.Color = RGB(255, 255, 0)
    Columns(Target.Column).Interior.Color = RGB(255, 255, 0)
End Sub

This colors the entire row and column of the active cell. Be aware that this can be visually overwhelming, so many users prefer a subtler color like light gray.

Excel for Mac and Excel for the Web

In Excel for Mac, the VBA editor is available (press Fn+Alt+F11 or go to Tools > Macro > Visual Basic Editor). The same VBA code works, but the keyboard shortcut differs: Option+F11 or Fn+Option+F11.

In Excel for the web, VBA macros are not supported. The conditional formatting method with the CELL function will work, but it will only update when the workbook recalculates (e.g., when you press F9 or edit a cell). There is no way to trigger recalculation on selection change in the web version, so the highlight will not follow your cursor. As of this writing, the web version does not support this feature natively.

Alternatives to Row Highlighting

If you do not want to use macros, consider these built-in alternatives:

  • Freeze Panes (View > Freeze Panes) to keep row labels visible while scrolling.
  • Table Styles (Ctrl+T) to add banded rows, which make it easier to follow a row visually.
  • Zoom to Selection (Alt+W, then Q) to enlarge the view of a specific range.
  • Name Box to type a row number and press Enter, which selects the entire row.

These do not highlight the active row, but they reduce the need for it.

Frequently Asked Questions

Can I highlight the row without using VBA? Yes, you can use conditional formatting with the CELL function, but it will only update when Excel recalculates. To make it update on selection change, you need a small VBA macro. Without VBA, the highlight will not follow your mouse clicks.

Will the VBA macro interfere with my existing cell colors? The simple macro shown above clears all interior fills, which will remove any colors you have manually set. To preserve them, you need a more complex macro that stores and restores original colors. Consider using conditional formatting if you have many pre-colored cells.

How do I stop the highlight from appearing on the entire row when I click a cell? Remove the VBA code or delete the conditional formatting rule. If you used the VBA macro, open the VBA editor, delete the code from the sheet module, and save the workbook.

Does this work in Google Sheets? No, this article is for Microsoft Excel. In Google Sheets, you can use conditional formatting with a custom formula, but there is no built-in way to detect the active cell. A Google Apps Script onSelectionChange event can achieve a similar effect, but it is a different implementation.

What if I only want to highlight the row up to the last column with data? Modify the VBA macro to use Range("A" & Target.Row & ":" & Cells(Target.Row, Columns.Count).End(xlToLeft).Address) to find the last used column in that row. This avoids coloring empty cells far to the right.

Highlighting the active row is a practical way to keep your place in dense spreadsheets. Whether you choose conditional formatting or VBA, test the method on a copy of your data first. Always save a backup before adding macros, and remember that macros cannot be undone with Ctrl+Z.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.