跳到主要内容

如何在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 关闭对话框,并且行根据值更改的特定列交替突出显示,请参见屏幕截图:


通过有用的功能根据值的变化为行交替着色

如果上述方法对您来说很难,您可以使用一个有用的工具-Kutools for Excel,其 区分差异 功能,您可以在Excel中根据组快速为行替换颜色。

提示:申请这个 区分差异 功能,首先,您应该下载 Kutools for Excel,然后快速轻松地应用该功能。

安装后 Kutools for Excel,请这样做:

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 Tab 为 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