Note: The other languages of the website are Google-translated. Back to English
登入  \/ 
x
or
x
註冊  \/ 
x

or

在Excel中單擊或選擇單元格時如何更改單元格顏色?

本文將向您展示一些方法,這些方法如何在單擊單元格時更改單元格顏色,並在Excel中選擇一系列單元格時更改突出顯示的顏色。

使用VBA代碼單擊單元格時更改單元格顏色
使用VBA代碼選擇單元格時更改突出顯示的顏色
用Kutools for Excel突出顯示活動單元格的整個行和列


使用VBA代碼單擊單元格時更改單元格顏色

在這裡,您可以使用以下VBA代碼雙擊或右鍵單擊單元格來更改其背景顏色。

1.在工作表中,單擊時將更改單元格顏色,右鍵單擊工作表選項卡,然後單擊 查看代碼 從右鍵單擊菜單中。

2。 在裡面 Microsoft Visual Basic for Applications 窗口,請複制以下VBA代碼並將其粘貼到 推薦碼 窗口。

VBA:單擊時更改單元格顏色

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

3。 按 其他 + Q 同時關閉按鍵 Microsoft Visual Basic for Applications 窗口。

然後,當您雙擊一個單元格時,它將被塗成紅色。 當您右鍵單擊一個單元格時,該單元格將變為綠色。 看截圖:


單擊以突出顯示Excel中所選單元格的行和列:

Kutools for Excel's 閱讀版式 實用程序可幫助您快速突出顯示Excel中所選單元格的行和列,如下面的演示所示。
立即下載並嘗試! (30天免費試用)


使用VBA代碼選擇單元格時更改突出顯示的顏色

默認情況下,選擇單元格範圍時,突出顯示的顏色為灰色。 如果要使所選範圍更加突出,可以將其突出顯示的顏色更改為所需的顏色。 請執行以下操作。

1.右鍵單擊要更改所選範圍的突出顯示顏色的圖紙選項卡,然後單擊 查看代碼 從右鍵單擊菜單中。

2。 在裡面 Microsoft Visual Basic for Applications 窗口,請複制以下VBA代碼並將其粘貼到 推薦碼 窗口。

VBA代碼:更改所選範圍的突出顯示顏色

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。 按 其他 + Q 按鍵同時關閉 Microsoft Visual Basic for Applications 窗口。

從現在開始,所選範圍或單元格的突出顯示顏色將變為黃色。 當您單擊另一個單元格或單元格範圍時,單元格將自動著色。


用Kutools for Excel突出顯示活動單元格的整個行和列

如果要處理較大的工作表,則必須突出顯示活動單元格的整個行和列,以便更輕鬆地閱讀。 在這裡 閱讀版式 的效用 Kutools for Excel 可以幫你。

申請前 Kutools for Excel首先下載並安裝.

1。 點擊 Kutools > 閱讀版式。 看截圖:

然後啟用閱讀佈局,您可以看到活動單元格的行和列立即突出顯示。

備註:您可以根據需要更改閱讀佈局設置,如下圖所示。

  如果您想免費試用該工具(30天), 請點擊下載,然後按照上述步驟進行操作。


用Kutools for Excel突出顯示活動單元格的整個行和列


最佳辦公效率工具

Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%

  • 重用: 快速插入 複雜的公式,圖表 以及您以前使用過的任何東西; 加密單元 帶密碼 創建郵件列表 並發送電子郵件...
  • 超級公式欄 (輕鬆編輯多行文本和公式); 閱讀版式 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不會丟失數據; 拆分單元格內容; 合併重複的行/列...防止細胞重複; 比較範圍...
  • 選擇重複或唯一 行; 選擇空白行 (所有單元格都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇...
  • 確切的副本 多個單元格,無需更改公式參考; 自動創建參考 到多張紙; 插入項目符號,複選框等...
  • 提取文字,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級濾鏡 (將過濾方案保存並應用於其他工作表); 高級排序 按月/週/日,頻率及更多; 特殊過濾器 用粗體,斜體...
  • 結合工作簿和工作表; 根據關鍵列合併表; 將數據分割成多個工作表; 批量轉換xls,xlsx和PDF...
  • 超過300種強大功能。 支持Office / Excel 2007-2019和365。支持所有語言。 在您的企業或組織中輕鬆部署。 完整功能30天免費試用。 60天退款保證。
kte選項卡201905

Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 每天將您的工作效率提高50%,並減少數百次鼠標單擊!
officetab底部
Say something here...
symbols left.
You are guest
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.
    Vera · 7 months ago
    Hi,
    is it possible to have a code for "change cell color when clicking on it" in the way that it will not change already formated cells with another color, please?
    After applying your code all my formating (colours) is away. Thank you. Veronika
  • To post as a guest, your comment is unpublished.
    kiba fil · 1 years ago
    Thank you. Great Job
  • To post as a guest, your comment is unpublished.
    shea honig · 1 years ago
    hi
    the is working grate but i want that the color should only be when the cell is selected and when i select something else, the first cell i selcted should not be colored
    can you help me pls with this thanks
    • To post as a guest, your comment is unpublished.
      Kris · 11 months ago
      I had that exact same question! I hope someone will answer you! The reason I am looking for this is I have a spreadsheet I use daily and put in lots of information into single cells. It gets hard to see the values (visually, it runs into info in other cells), and would be a great feature if I could change the color of the cell being edited - only while it is being edited. The simplest solution I can think of is that the cell value would be set back to what it was prior to being clicked on - but I don't know how to do that.
  • To post as a guest, your comment is unpublished.
    perry · 1 years ago
    Hi, I am trying to figure out how to change the color of a cell, based on a selection from a dropdown list. For example, HIGH=red, MEDIUM=yellow, LOW=green.

    Any tips you can provide are greatly appreciated. Thank You
  • To post as a guest, your comment is unpublished.
    Vishnu Subind · 1 years 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 · 1 years 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 · 1 years ago
    trimakasih
  • To post as a guest, your comment is unpublished.
    rahayu · 1 years ago
    td muncul=tidak muncul
  • To post as a guest, your comment is unpublished.
    rahayu · 1 years 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.
    vuongngocsangbkdn@gmail.com · 2 years 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 · 2 years ago
      Good day,
      Sorry can't help you with that. Thanks for commenting.
  • To post as a guest, your comment is unpublished.
    devika.kalika@gmail.com · 2 years 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 · 2 years 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 · 2 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 · 2 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 · 2 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 · 2 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 · 3 years ago
    thank you thank you so much. I appreciate you for this.