How to Highlight Active Row in Excel (3 Methods)

We’ll use the following sample dataset to highlight a row whenever we select a cell in that row.

DATASET


Method 1 – Highlighting the Active Row by Using Conditional Formatting in Excel

  • Select your entire worksheet by clicking on the top-left corner of the sheet.

SELECT ENTIRE SHEET

  • Go to Home, choose Conditional Formatting, and select New Rule.

  • This will open the New Formatting Rule window.
  • Select Use a formula to determine which cells to format from Select a Rule Type.
  • A new box named Format values where this formula is true will appear in the bottom part of the New Formatting Rule window.
  • Use the following formula in the Format values where this formula is true box:
=CELL("row")=CELL("row",A1)
  • Click on Format to set the color for highlighting.

Conditional formatting

  • A new window named Format Cells will appear.
  • Select a color with which you want to highlight the active row from the Fill tab.
  • You can also set different number formatting, font, and border styles for the active row in the other tabs of the Format Cells window if you want to.
  • Click on OK.

SELECT COLOR

  • You will see your selected formatting style in the Preview box of the New Formatting Rule window.
  • Click on OK.

CONDITIONAL FORMATTING

  • Select any cell of your dataset.
  • The entire row of the active cell will be highlighted with your selected color.

HIGHLIGHT ACTIVE ROW IN EXCEL

  • If you select a cell from any other row, you will see the first row is still highlighted.

This is happening because Excel hasn’t refreshed itself. Excel automatically refreshes itself when a change is made in any cell or when a command is given. But it doesn’t refresh automatically when you just change your selection. So, you need to refresh Excel manually.

HIGHLIGHT ACTIVE ROW IN EXCEL

  • Press F9.
  • Select a cell and press F9 to highlight the active row and remove previous highlights.

HIGHLIGHT ACTIVE ROW IN EXCEL


Method 2 – Using VBA to Highlight Rows with Active Cell in Excel

  • Right-click on the sheet name (VBA) where you want to highlight the active row.
  • Select View Code.

CODE

  • This will open the VBA window. You will see the Code window of that sheet.

CODE WINDOW

  • Insert the following code in the window.
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Static xRow

If xRow <> "" Then
    With Rows(xRow).Interior
        .ColorIndex = xlNone
    End With
End If

Active_Row = Selection.Row
xRow = Active_Row
With Rows(Active_Row).Interior
    .ColorIndex = 7
    .Pattern = xlSolid
End With

End Sub

The code will change the color of the row with the selected cell with a color that has color index 7. If you want to highlight the active row with other colors, insert a number other than 7 in the .colorIndex value.

  • Close or minimize the VBA window.
  • If you select a cell, the whole row will be highlighted.

HIGHLIGHT ACTIVE ROW IN EXCEL

  • Select another cell from a different row.
  • The new row will be highlighted instead.

HIGHLIGHT ACTIVE ROW IN EXCEL

Read More: How to Highlight Entire Row in Excel with Conditional Formatting


Method 3 – Automatically Highlight the Active Row Using Conditional Formatting and VBA

  • Go to the Formulas tab and select Define Name.

DEFINE NAME

  • This will open the New Name window.
  • Type a name (for example HighlightActiveRow) in the Name box and put =1 in the Refers to box.
  • Press OK.

NAME

  • Select the entire worksheet by clicking on the top-left corner of the sheet.

ENTIRE SHEET SELECTION

  • Go to Home, then to Conditional Formatting, and select New Rule.

CONDITIONAL FORMATTING

  • This will open the New Formatting Rule window.
  • Select Use a formula to determine which cells to format from the Select a Rule Type box.
  • A new box named Format values where this formula is true will appear in the bottom part of the New Formatting Rule window.
  • Use the following formula in the Format values where this formula is true box:
=ROW(A1)=HighlightActiveRow
  • Click on Format to set the color for highlighting.

HIGHLIGHT ACTIVE ROW IN EXCEL

  • Select a color with which you want to highlight the active row from the Fill tab. You can also other formatting options by going to the different tabs of the Format Cells window.
  • Click on OK.

HIGHLIGHT ACTIVE ROW IN EXCEL

  • Click on OK again.

HIGHLIGHT ACTIVE ROW IN EXCEL

  • Right-click on the sheet name (CF & VBA) where you want to highlight the active row.
  • Select VIew Code.

HIGHLIGHT ACTIVE ROW IN EXCEL

  • Insert the following code in the VBA window that was opened.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    With ThisWorkbook.Names("HighlightActiveRow")
   .Name = "HighlightActiveRow"
   .RefersToR1C1 = "=" & ActiveCell.Row
    End With

End Sub

The code will automate the refreshing process. The name (HighlightActiveRow) must be the same as the name you have given in the Define Name box.

HIGHLIGHT ACTIVE ROW IN EXCEL

  • Close or minimize the VBA window.
  • If you select a cell, the whole row will be highlighted.

HIGHLIGHT ACTIVE ROW IN EXCEL

  • If you select another cell, only the row of that cell will be highlighted.

HIGHLIGHT ACTIVE ROW IN EXCEL


Download the Practice Workbook


Related Articles


<< Go Back to Highlight Row | Highlight in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Prantick Bala
Prantick Bala

PRANTICK BALA is a marine engineer who loves exploring Excel and VBA programming. Programming, to him, is a time-saving tool for efficiently managing data, files, and internet tasks. He is proficient in Rhino3D, Maxsurf, C++, MS Office, AutoCAD, Excel, and VBA and goes beyond the basics. Armed with a B.Sc in Naval Architecture & Marine Engineering from BUET, he has transitioned into the role of a content developer. Beyond his work, find him immersed in books, exploring new... Read Full Bio

21 Comments
  1. Thank you for the crystal clear instructions. I just wanted to point out an error in section 3.1, under “Type the following formula in the Format…”. Your Conditional Formatting formula shows “=CELL(A1)=HighlightActiveRow” which doesn’t work when combined with the VBA. It should be “=Row(A1)=HighlightActiveRow”, like you show in the image after.

  2. Hi, Thanks a lot for this article! Can I also make method B work for all sheets that I’m using? It already works well for the current sheet. I already have a personal.xlsb and an add-in (for UDFs), but inserting the code into a new module here, won’t work.

    • Hi Henrik, to highlight rows in Excel, you need to apply VBA code in that certain worksheet like this article. Otherwise, you need to run the code every time when you go to the next row and highlight it. This is a major disadvantage of this method. If you need to apply in all the worksheets, then you need to utilize the following code.

      Sub Highlights_Active_Row()
      Static xRow
      If xRow <> “” Then
      With Rows(xRow).Interior
      .ColorIndex = xlNone
      End With
      End If
      Active_Row = Selection.Row
      xRow = Active_Row
      With Rows(Active_Row).Interior
      .ColorIndex = 7
      .Pattern = xlSolid
      End With
      End Sub

      Note: Remember every time you go to the next row, you have to run the code every single time.

  3. The only thing I’m struggling with is it won’t let me undo (ctrl + z) anything with the last method. Any suggestions?

    • Hi Amber, You can’t undo anything after applying the VBA code. This is one of the drawbacks of Excel.

  4. Hi! I used option 2 with VBA only because the other options didn’t work with my document. The only problem is when I reopen the excel doc after closing it, the row of the last active cell stays highlighted no matter which cell I click. So, I end up with two highlighted, one row that’s constantly highlighted and the other one changes with the chosen active cell. How do I fix this?

    • Hello JULIE, thanks for your feedback. Use the below code to fix that-

      Sub Worksheet_SelectionChange(ByVal Target As Range)
      Static xRow
      Cells.Interior.ColorIndex = 0
      If xRow “” Then
      With Rows(xRow).Interior
      .ColorIndex = xlNone
      End With
      End If
      Active_Row = Selection.Row
      xRow = Active_Row
      With Rows(Active_Row).Interior
      .ColorIndex = 7
      .Pattern = xlSolid
      End With
      End Sub

      *Or you can use an alternative way with the previous code, after opening the file, click on any cell on the previously highlighted row, and then only the active row will be highlighted.

  5. hi, I have used the VBA option as well (option 2), my only issue is if you click the titles of my table which is a different colour it then removes all the formatting of that, is there any way to add a range to the VBA to make it so this only works for certains cells or return it back to its original colour when not the active row?

    • Hello, DALE HALL!
      Thanks for sharing your problem with us!
      You can set a range of cells to highlight using the following VBA code.

      Sub Highlight()
      For Each cell In Range("A5:A8")
           cell.EntireRow.Interior.ColorIndex = 6
      Next
      End Sub

      Hope this will help you!
      Good Luck!

      Regards,
      Sabrina Ayon
      Author, ExcelDemy
      .

  6. hi
    my excel dose not accept the formula’
    it shows this message:
    “we found a problem with this formula…
    first i copied the formula, then i typed it manually,
    still dosen’t work.

    • Hello Behzad,
      Thank you for your question. We’re sorry to hear that you’re facing difficulties with the formula. In fact, the ExcelDemy team has tested the Excel file following your comment and the formula appears to be working correctly.

      That said, it would be helpful if you could send us a screenshot of the issue that you’re experiencing.

  7. HELLO CAN YOU DO ME A FAVOR.
    IS THERE ANY WAY TO HIGHLIGHT ROWS AND COLUMNS OF MULTIPLE ACTIVE CELLS ONLY USING CONDITIONAL FORMATTING. SUCH AS WHEN SELECTING FROM C4 TO F10, ALL THE ROWS FROM 4 TO 10 AND ALL THE COLUMNS FROM C TO F GETS HIGHLIGHTED. IT WILL BE A GREAT HELP. THANK YOU.

  8. Hello FAHIM,

    Yes, it is possible to highlight rows and columns of multiple active cells using conditional formatting in Microsoft Excel. To do so, you can use the following steps:

    1. Initially, select the cells you want to apply the conditional formatting to.
    2. Afterward, go to the Home tab and click the Conditional Formatting button in the Styles group.
    3. Later, choose New Rule from the drop-down menu.
    4. Next, select “Use a formula to determine which cells to format.”
    5. Meanwhile in the formula box, enter the following formula:
    =ROW()>=MIN(ROW($C$4:$F$10))
    6. Further, click the Format button and select the fill color you want to use.
    7. Lastly, click OK to close the Format Cells dialog box.
    This approach uses a relative reference for the row and column in the formula, allowing the conditional formatting to adjust automatically as cells are selected.

  9. Hi I inserted the code for the following:

    2. Highlight Row with Active Cell in Excel Using VBA

    When I click on a cell it gives the following error:

    “Run-time error ‘1004’:

    Application-defined or Object-defined error”

    If I press “Debug” it displays a yellow arrow at:
    .ColorIndex = 7

    • Hello KOBUS,
      Thank you for your question. We’re sorry to hear that you’re facing difficulties with the VBA code. In fact, the ExcelDemy team has tested the Excel file and the code with other workbooks following your comment and the code appears to be working correctly.
      However, you can check the following 2 steps.
      1. Follow the individual steps properly.
      2. You have to insert the code by using the View Code option of a particular sheet. It will not work if you insert it in a VBA Module.
      I hope this will solve your issue. If you still face problems, please feel free to comment again or send your workbook so that I can check the issue.

  10. hello, i have used the vba option too (option 2), my only problem is if you click on the titles of my table which has a different color then it removes all the formatting from that,Is it possible to automatically change the color back that was in the cell ?

    • Reply Mahfuza Anika Era
      Mahfuza Anika Era Feb 28, 2024 at 1:05 PM

      Hello BRAM,
      If you are using the VBA option, the colour of the table header should be automatically changed to the previous colour right after selecting another cell. Please check if you have written the code correctly. Following is the gif for your understanding.

      If your problem is not yet solved, please join our ExcelDemy Forum and post this problem with your Excel file attached to it.

      Regards,
      Mahfuza Anika Era
      Exceldemy

  11. Is it possible to automatically change the color back to the collor that was in the cell ? Grtzz

  12. This is applicable only within the Table. Formatting outside a Table will be undone. Please advise on how to remedy this.

    • Hello Kelly,

      To extend the Highlight Active Row functionality outside a table, you can apply Conditional Formatting using a formula. Here’s how:

      1. Select the entire range (or the rows you want to highlight).
      2. Go to Home > Conditional Formatting > New Rule.
      3. Choose “Use a formula to determine which cells to format.”
      4. Enter the formula: =ROW()=CELL(“row”)
      5. Select your preferred format.
      This will highlight the active row across the selected range, even outside of tables.

      Regards
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo