跳到主要內容

如何在Excel中根據組替換行顏色?

在Excel中,為其他大多數人著色可能對我們大多數人來說都比較容易,但是,您是否曾經嘗試過根據列值的變化來為行分別著色–列A如下面的截圖所示,在本文中,我將討論根據Excel中的組替換行顏色。

根據使用輔助列和條件格式設置的值更改為行交替著色

通過有用的功能根據值的變化為行交替著色

根據助手列和條件格式設置的值更改,為行交替著色兩種顏色


根據使用輔助列和條件格式設置的值更改為行交替著色

要基於組交替突出顯示行,您沒有直接的方法,因此您需要創建一個幫助器列,然後應用條件格式設置功能為它們上色。 請執行以下操作:

1。 在單元格D1的標題的同一行中,輸入數字 0.

2。 在單元格D2中,鍵入以下公式: =IF(A2=A1,D1,D1+1) ,然後將此公式向下拖動到要應用該公式的單元格上,請參見屏幕截圖:

備註:在以上公式中, A1, A2 是該列的第一個和第二個單元格,其值會發生變化, D1 是您輸入幫助程序編號0的單元格。

3。 然後選擇數據范圍A2:D18,其中包括幫助程序公式列,然後單擊 首頁 > 條件格式 > 新規則,請參見屏幕截圖:

4。 在 新格式規則 對話框中選擇 使用公式來確定要格式化的單元格 選擇規則類型 部分,然後輸入此公式 = AND(LEN($ A2)> 0,MOD($ D2,2)= 0)格式化此公式為真的值 文本框,請參見屏幕截圖:

備註: A2 是您根據其進行著色的列的第一個單元格,並且 D2 是您在所選範圍內創建的幫助程序列的第一個單元格

5。 然後點擊 格式 按鈕去 單元格格式 對話框,然後在 標籤,請參見屏幕截圖:

6。 然後點擊 OK > OK 關閉對話框,並且行根據值更改的特定列交替突出顯示,請參見屏幕截圖:


通過有用的功能根據值的變化為行交替著色

如果上述方法對您來說很難,您可以使用一個有用的工具-Excel的Kutools,其 區分差異 功能,您可以在Excel中根據組快速為行替換顏色。

提示:要應用此 區分差異 功能,首先,您應該下載 Excel的Kutools,然後快速輕鬆地應用該功能。

安裝後 Excel的Kutools,請這樣做:

1。 點擊 庫工具 > 格式 > 區分差異,請參見屏幕截圖:

2。在裡面 按鍵列區分差異 對話框,請根據需要執行以下操作。 看截圖:

3完成設置後,單擊 Ok 按鈕關閉對話框,您將根據需要獲得以下結果:

點擊下載Kutools for Excel並立即免費試用!


根據助手列和條件格式設置的值更改,為行交替著色兩種顏色

如果您要根據值變化以兩種不同的顏色交替著色行,如下面的屏幕截圖所示,這也可以在Excel中使用條件格式解決。

1。 首先,您應該創建一個新的幫助器列和公式作為第1步到第2步的第一種方法,您將獲得以下屏幕截圖:

2。 然後選擇數據范圍A2:D18,然後單擊 首頁 > 條件格式 > 管理規則,請參見屏幕截圖:

3。 在 條件格式規則管理器 對話框,單擊 新規則 按鈕,請參見屏幕截圖:

4。 在彈出 新格式規則 對話框中單擊 使用公式來確定要格式化的單元格選擇規則類型,然後輸入此公式 = ISODD($ D2) (D2 是您創建公式的幫助器列的第一個單元格),然後單擊 格式 按鈕,為組的奇數行選擇所需的填充顏色,請參見屏幕截圖:

5。 然後點擊 OK 退出此對話框以返回前一個對話框 條件格式規則管理器 對話框,請單擊 新規則 再次單擊可為組的偶數行創建另一個規則。

6。 在 新格式規則 對話框,單擊 使用公式來確定要格式化的單元格選擇規則類型 和以前一樣,然後輸入此公式 =伊斯文($ D2) (D2 是您創建公式的幫助器列的第一個單元格),然後單擊 格式 按鈕為組的偶數行選擇另一種背景顏色,請參見屏幕截圖:

7。 然後點擊 OK 返回 條件格式規則管理器,您會看到兩個規則如下創建:

8。 然後點擊 OK 關閉此對話框,您會看到您選​​擇的數據范圍已根據列值的更改以兩種不同的顏色交替著色。

  • 筆記:
  • 1.交替為行著色後,您可以根據需要隱藏幫助器列,但不能將其刪除。
  • 2.如果數據范圍中沒有標題,則只需在幫助器列中輸入1作為第一個數字,然後照常應用幫助器公式。

更多文章:

  • 當值在另一列中更改時增加數字
  • 假設您在A列中有一個值列表,現在想在A列中的值更改時在B列中將數字遞增1,這意味著B列中的數字遞增直到A列中的值更改,然後數字增量再次從1開始,如左圖所示。 在Excel中,您可以使用以下方法解決此任務。
  • 在Excel中值更改時插入空白行
  • 假設您具有一定範圍的數據,現在您想在值更改時在數據之間插入空白行,以便可以將一列中的順序相同值分開,如下面的屏幕截圖所示。 在本文中,我將為您解決一些技巧。
  • 值在另一列中更改時對單元格求和
  • 有時,當您處理Excel工作表時,可能需要根據另一列中的數據組對單元格求和。 例如,在這裡,我想對A列中的數據更改時B列中的訂單求和以獲得以下結果。 您如何解決Excel中的這個問題?
  • 在Excel中值更改時插入分頁符
  • 假設我有一個單元格區域,現在,當A列中的值發生變化時,我想在工作表中插入分頁符,如左圖所示。 當然,您可以一個接一個地插入分頁符,但是有沒有一種快速的方法可以根據一列的更改值一次插入分頁符?

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


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

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (17)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
is it possible to make this work when you use filters? if i apply a filter and the helper column are both 2 different odd numbers, then both rows have the same color.... how can we make this apply to filtered data, and still work when unfiltered?
This comment was minimized by the moderator on the site
Hey, thanks for the help. I tried this and the coloring is off by one. Any ideas?
This comment was minimized by the moderator on the site
Modify the formula to apply the conditional formatting to the header as well.=AND(LEN($A1)>0,MOD($D1,2)=0)
This works better for me than trying to highlight just my data rows.
This comment was minimized by the moderator on the site
When you highlight the selection don't highlight the header row.
This comment was minimized by the moderator on the site
I hate helper columns. I'd rather have a huge formula before I put in a helper column. Sometimes Macros are easier, but I'm not always allowed to use macro enabled spreadsheets. When I want to use a macro, I usually run it from my Personal.xlsb, but that doesn't really help with avoiding a helper column.
This comment was minimized by the moderator on the site
Thank you very much for this, it was much appreciated.
This comment was minimized by the moderator on the site
just use 1-prev_value, and you get alternating 1 and 0 s
This comment was minimized by the moderator on the site
Thanks for this formula, been thinking it wasn't possible for a while. Here's a question: Can you format each group to be a different color? Or are you limited to 2 alternating colors?

Thanks!
This comment was minimized by the moderator on the site
Great piece of information. you helped me to present my analysis results better.
This comment was minimized by the moderator on the site
Thank you so much for this post, I've wanted to be able to change row color based on group for a long time. Easy to follow and much appreciated!
This comment was minimized by the moderator on the site
This formula (when used in conditional formatting) would alternate the row color based on group without the assistance of a helper row: =ISODD(SUMPRODUCT(1/COUNTIF($A$1:$A2,$A$1:$A2)))
This comment was minimized by the moderator on the site
This formula works great if your table only has 100 rows. But it really slows down when you have 5,000 rows. Any suggestions to speed up the formula on larger datasets?
This comment was minimized by the moderator on the site
Hello, Barb,
You can try the below formula:
=MOD(SUMPRODUCT(--($A$1:$A1<>$A$2:$A2)),2)


Note: When you select the data range, please exclude the first header row.

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Fantastic! Well done!
This comment was minimized by the moderator on the site
Justin, your formula is nice because it doesn't require a helper column, but for some reason it requires extra RAM and slows the workbook down noticeably. I would recommend using the formula given in the article and just dealing with the helper column.
This comment was minimized by the moderator on the site
Hi Justin. When I use either the helper row method or yours, it formats one row off. Do you know why?
This comment was minimized by the moderator on the site
More than likely - as I did - you selected the whole columns, and not just the data (excl. any headings)
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations