It is common to lose your way in a big table of data. Even though Excel's freezing features help you to display selected row and column's primary data, no feature can beat highlighting to express the selected data. In this guide, we’re going to show you how to highlight selected row and column in Excel.

Download Workbook

Dynamic highlighting in Excel can be done by Conditional Formatting with ease. If you are not familiar with the conditional formatting, it is feature that allows you to change cells formatting based on a formula or value of cells.

You can apply the formatting into an entire row or column. However, Excel doesn't have a built-in function that returns the address of a selected cell. Thanks to VBA, we are not out of options. You can send the selected cell's row and column information to cells or named ranges by four-row code that you can either type or copy-paste. Follow the steps to highlight selected row and column in Excel.

1. Named ranges

Start by creating 2 named ranges. Named ranges allows you a simple formula writing and reading both in the worksheet and VBA Editor. Just select a cell and give a friendly name which refers the selected row. For example, "SelectedRow".

All you need to do is to select a cell and type desired name into the reference box near the formula bar. You can learn more about ways of creating named ranges in 5 Ways to Create an Excel Named Range article.

Create a named range for selected column as well, e.g., "SelectedCol".

2. VBA

Open VBA window by pressing Alt + F11 key combination. You can click Visual Basic icon under Development tab as well.

If you do not see the Developer tab in your Ribbon, take a look this article: How to display the Excel Developer tab for using advanced features

  1. Once VBA window is open, double click on the worksheet including the data you want to highlight. This action opens the worksheet's editor at the right side.
  2. Select Worksheet item in the drop down at the left. This step will add Worksheet_SelectionChange event to your editor.
  3. The code under Worksheet_SelectionChange event is evaluated whenever the user selects a different cell. Either write or copy paste the following code block between "Private Sub …" and "End Sub" lines.
    [SelectedRow] = Target.Row
    [SelectedCol] = Target.Column
    How to highlight selected row and column in Excel 04

As you can figure out quickly the names between brackets refer the named ranges you created at the first step. Thus, feel free to replace them if you named your cells differently. You can learn more about how you can refer a cell or range in VBA in How to refer a range or a cell in Excel VBA.

Once the code is ready, you can close the VBA window. You can see the effect directly in your worksheet. The cells you named will show the selected cell's row and column numbers whenever you select a cell.

3. Conditional formatting

Since we know the selected cell's coordinates, it is easy to set a conditional formatting rule.

  1. Select the data you want to highlight.
  2. Open conditional formatting window by clicking Home > Styles > Conditional Formatting > New Rule.
  3. Select Use a formula to determine which cells to format rule.
  4. Type the formula which checks if the row of the cell in the data is equal the value in the "SelectedRow" cell. The reference in the ROW function should be the top-left cell of the data and a relative reference. Thus, no $ signs in the reference. Otherwise, the rule will be applied to that cell only.
  5. Select the desired highlight color in the dialog you can reach by Format
  6. Click OK to save the rule.
  7. You can see the effect directly.
    How to highlight selected row and column in Excel 08 Row only
  8. Add another rule for the column. This time the formula should be like this:
    How to highlight selected row and column in Excel

That's the way of highlighting selected row and column in Excel with help of VBA.