Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Highlighting the Rows of Selected Cells.

Highlighting the Rows of Selected Cells

Written by Allen Wyatt (last updated May 12, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021


8

Sometimes it is easy to lose track of where the selected cell is located in a worksheet. There are several ways you can locate the cell, but sometimes it would be handy to just have a way to highlight the whole row of the selected cell.

The easiest way to do this in Excel is to press Shift+Space Bar. The entire row is highlighted, and the selected cell remains the same. If you want to move to another cell in the same row (without changing the highlight), you can use Tab to move to the right and Shift+Tab to move to the left.

If you prefer to have Excel automatically highlight the row, you must rely upon a macro. The following one will do the trick:

Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Static rr
    Static cc

    If cc <> "" Then
        With Columns(cc).Interior
            .ColorIndex = xlNone
        End With
        With Rows(rr).Interior
            .ColorIndex = xlNone
        End With
    End If

    rr = Selection.Row
    cc = Selection.Column

    With Columns(cc).Interior
        .ColorIndex = 20
        .Pattern = xlSolid
    End With
    With Rows(rr).Interior
        .ColorIndex = 20
        .Pattern = xlSolid
    End With
End Sub

Make sure you attach the macro to the worksheet you are using at the time. All the code does is highlight the row and column the active cell is at. When moving to another cell, the code remembers the previous cell (by using variables declared as Static) and removes the highlighting from the previous rows and columns. This code highlights both the current row and column. For just highlighting the row, remove the chunks of code with cc in them. The only real problem with this method is that if your sheet has any previous color-filled cells, these will be changed to NoFill, erasing any color that was there.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10367) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Excel here: Highlighting the Rows of Selected Cells.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Two-Line Headings in a TOC

If you use the TC field to mark what goes in a TOC, you may wonder why if you mark two lines together with the field they ...

Discover More

Printing Return Address Labels

Want an easy way to create your own return address labels? Word provides the tool as a feature of the program.

Discover More

Removing Return Addresses

Word allows you to print return addresses on your envelopes. You may run across a scenario where the return address is ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Easily Dividing Values by 1000

Sometimes the data in a worksheet isn't in the exact format desired. If you want to divide your values by 1,000, there ...

Discover More

Quickly Entering Dates and Times

Excel provides keyboard shortcuts for a variety of purposes. This tip examines two such shortcuts, designed to allow ...

Discover More

Proper Case Conversion with Exceptions

The PROPER worksheet function allows you to change the case of text so that only the first letter of each word is ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine minus 1?

2025-05-16 05:18:21

Mike J

@Mike H

I believe that Microsoft365 has only had this feature for about 6 months, and needs an annual subscription.

This tip has made it available to non-subscription users for about 6 years - for nothing! It works fine in Excel2010, and probably earlier.


2025-05-13 10:09:51

Mike H

I believe this is no longer necessary with the recent advent of View Tab - Focus Cell


2019-08-19 10:30:52

Willy Vanhaelen

In his comment of 7 June 2018 Samuel is right, as well this tip's macro as my version in the previous post make the undo stack non functional. It is possible though to accomplish the highlighting with conditional formatting instead of by using these macros. Here is how:
- Select the range for which you want to apply the formatting (e.g. the whole sheet).
- Click "Conditional Formatting" in the "Styles" section of the ribbon's "Home" tab.
- Select "New Rule" and then choose "Use a formula to determine which cells to format".
- In the box "Format values where this formula is true:" enter the following formula:
=CELL("row")=ROW() for highlighting only the entire row
=OR(CELL("row")=ROW(),CELL("col")=COLUMN()) for both row and column.
- Click the "Format" button and select the "Fill" tab.
- Select the color you want and click OK three times.

This conditional formatting does however require a recalc in order to function properly. This can be done by this event macro:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Calculate
End Sub

The Target.Calculate statement doesn't affect the undo stack which remains functional.


2019-08-15 12:03:26

Willy Vanhaelen

Here is a simplified version of this tip's macro:

Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Static X As Long
Static Y As Long
If X <> 0 Then
Columns(X).Interior.ColorIndex = xlNone
Rows(Y).Interior.ColorIndex = xlNone
End If
X = Target.Column
Columns(X).Interior.ColorIndex = 20
Y = Target.Row
Rows(Y).Interior.ColorIndex = 20
End Sub

And if you only want the row to be highlighted (as I do), this little macro will do the job:

Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Static Y As Long
If Y <> 0 Then Rows(Y).Interior.ColorIndex = xlNone
Y = Target.Row
Rows(Y).Interior.ColorIndex = 20
End Sub


2018-06-07 05:43:54

samuel

Thanks great and simple tool. although i noticed that it doesn't allow undo (Ctrl+Z) and auto save. perhaps you could look into it


2018-01-03 00:40:24

Syed

Thank you great


2016-12-06 14:34:54

Mark Strohmeyer

I like that there is no conditional formatting associated with this code.

How can I modify the VBA to highlight the row to the left and the column up?

Is there a way to keep the VBA from overwriting any other non conditional color formatting I am using?

Thanks, Mark


2015-10-08 09:38:09

Louis LAFRUIT

Personnaly I increase the heigth of that row.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.