Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to change cell color when cell is clicked or selected in Excel?

This article will show you some methods of how to change cell color while clicking on a cell, and change the highlighted color while selecting a range of cells in Excel.

Change cell color when cell is clicked with VBA code

Change the highlighted color when cells are selected with VBA code

Highlight entire row and column of active cell with Kutools for Excel


One click to highlight row and column of selected cell in Excel:

Kutools for Excel's Reading Layout utility helps you quickly highlight row and column of selected cell in Excel. See screenshot: Download the full feature 60-day free trail of Kutools for Excel now!

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download the free trial Now!

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

Change cell color when cell is clicked with VBA code

Here, you can change the background color of a cell when double clicking it or right clicking on it with the following VBA code.

1. In the worksheet you will change the cell color when clicking on it, right click the sheet tab and click View Code from the right-clicking menu.

2. In the Microsoft Visual Basic for Applications window, please copy and paste the below VBA code into the Code window.

VBA: change cell color when clicking on it

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    Target.Interior.Color = vbRed
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    Target.Interior.Color = vbGreen
End Sub

3. Press Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window.

Then, when you double click a cell, it will be colored in red. And when you right click on a cell, it will be colored in green. See screenshot:


Change the highlighted color when cells are selected with VBA code

By default, when selecting a range of cells, the highlighted color is gray. If you want to make the selected range more standing out, you can change its highlighted color to the one you need. Please do as follows.

1. Right click the sheet tab you want to change the highlighted color of the selected range, and click View Code from the right-clicking menu.

2. In the Microsoft Visual Basic for Applications window, please copy and paste the below VBA code into the Code window.

VBA code: change the highlighted color of selected range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Target
        .Worksheet.Cells.FormatConditions.Delete
        .FormatConditions.Add xlExpression, , "TRUE"
        .FormatConditions(1).Interior.Color = vbYellow
    End With
End Sub

3. Press Alt + Q keys at the same time to close the Microsoft Visual Basic for Applications window.

From now on, the highlighted color of selected range or cell is changed to yellow. When you click another cell or range of cells, the cells will be colored automatically.


Highlight entire row and column of active cell with Kutools for Excel

If you are dealing with a large worksheet, it is necessary to highlight the entire row and column of the active cell in order to make reading more easily. Here the Reading Layout utility of Kutools for Excel can help you.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 60 days. 

1. Click Kutools > Reading Layout. See screenshot:

Then the reading layout is enabled, you can see the row and column of active cell are highlighted immediately.

Note: You can change the reading layout settings based on your needs as below screenshot shown.

Tip.If you want to have a free trial of this utility, please go to download the software freely first, and then go to apply the operation according above steps.


Office Tab - Tabbed Browsing, Editing, and Managing of Workbooks in Excel:

Office Tab brings the tabbed interface as seen in web browsers such as Google Chrome, Internet Explorer new versions and Firefox to Microsoft Excel. It will be a time-saving tool and irreplaceble in your work. See below demo:

Click for free trial of Office Tab!

Office Tab for Excel


Highlight entire row and column of active cell with Kutools for Excel

Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 60 days. Download the free trial now!


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Vishnu Subind · 5 months ago
    Hi guys, so i used to first code to change the cell colour to green/red on doubleclick/rightclick. I would like this code, however, to work just on a specific range of cells, in my case D9:P9. can someone help me on how to do that? Im new at VBA
    • To post as a guest, your comment is unpublished.
      crystal · 2 months ago
      Hi,
      The below VBA code can do you a favor, please have a try. Thank you for your comment.

      Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      If (Not Application.Intersect(Target, Me.Range("D9:P9")) Is Nothing) Then
      Cancel = True
      Target.Interior.Color = vbRed
      End If
      End Sub
      Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
      If (Not Application.Intersect(Target, Me.Range("D9:P9")) Is Nothing) Then
      Cancel = True
      Target.Interior.Color = vbGreen
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    rahayu · 8 months ago
    trimakasih
  • To post as a guest, your comment is unpublished.
    rahayu · 8 months ago
    td muncul=tidak muncul
  • To post as a guest, your comment is unpublished.
    rahayu · 8 months ago
    Salam...
    sy sudah install kutools, tp kok td muncul tab kutools di layar excel ya? gmn cara mmunculkannya?trimakasih
  • To post as a guest, your comment is unpublished.
    Cr Decima · 9 months ago
    I have a problem.
    I want change color of one hyperlink if it had linked with one PDF to RED and if had not link with one PDF will show BLUE color.
    How can I do now?
    • To post as a guest, your comment is unpublished.
      crystal · 9 months ago
      Good day,
      Sorry can't help you with that. Thanks for commenting.
  • To post as a guest, your comment is unpublished.
    Devika Kalika · 10 months ago
    I tried the "Change the highlighted color when cells are selected with VBA code" option and saved my excel as Macro Enabled Worksheet. Now the last cells that were selected are highlighted and won't highlight other cells when selected. I've deleted code and reentered and saved, but still no change. I can't remove the previous highlight either. I'm at lost on what to do.
    • To post as a guest, your comment is unpublished.
      crystal · 10 months ago
      Hi,
      The code works well in my case after saving the workbook as an Excel Macro-Enabled Workbook.
      Can you tell me your Excel version?
  • To post as a guest, your comment is unpublished.
    Jason · 1 years ago
    Is there a way to just apply this to certain cells while leaving other cells with available for number entering?
  • To post as a guest, your comment is unpublished.
    Slaxx · 1 years ago
    hi. just a little heads up. i'm using office 2007.
    i tried your code, and while it did work, it wasn't what i was looking for. so i just deleted the code completely. but the last selected/active cell before i deleted the code is still green (i changed the color from vbYellow to vbGreen), and the color won't go away. it's not affected by fill color either.
    the simplest solution i found was to just delete the cell. copying and pasting will not work, it will also copy the color.
    just thought i'd let you know. you might find another solution/troubleshooting for this, besides deleting and manual entry. still, thanks! i confirm that the code works :)
  • To post as a guest, your comment is unpublished.
    Michelle · 1 years ago
    I love how easy formatting my worksheet the code for "change cell color when clicking on it" would make my daily work! I am hitting a snag though. When I copy my Blank Sheet with the code entered as described, I get a error. It runs great until I create new sheets. I am a novice at coding and am working from textbooks and the internet. I appreciate any help you will offer!
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Michelle,
      I followed the steps as you described, but the code also worked in my case. Can you tell me your Office version?
      Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    madhav neupane · 1 years ago
    thank you thank you so much. I appreciate you for this.