excel - 在 Excel 中交替着色行组

标签 excel vba colors

我有一个像这样的 Excel 电子表格

id | data for id
   | more data for id
id | data for id
id | data for id
   | more data for id
   | even more data for id
id | data for id
   | more data for id
id | data for id
id | data for id
   | more data for id

现在我想通过交替行的背景颜色来对一个id的数据进行分组

var color = white
for each row
    if the first cell is not empty and color is white
        set color to green
    if the first cell is not empty and color is green
        set color to white
    set background of row to color

任何人都可以帮我编写宏或一些 VBA 代码吗

谢谢

最佳答案

我使用此公式来获取条件格式的输入:

=IF(B2=B1,E1,1-E1))    [content of cell E2]

其中B列包含需要分组的项目,E是辅助列。每当上部单元格(本例中为 B1)与当前单元格 (B2) 相同时,就会返回 E 列的上部行内容。否则,它将返回 1 减去该内容(即输出将为 0 或 1,具体取决于上面单元格的值)。

enter image description here

enter image description here

enter image description here

关于excel - 在 Excel 中交替着色行组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27020/

相关文章:

vba - Worksheet_change 似乎没有触发

excel - ShapeRange、Chart、ChartArea 和 PlotArea 是什么关系

Excel VBA : Communicating via named pipe

vba - 将 Excel 工作表(部分)的范围导出到 CSV

excel - VBA excel函数

C# 并定义通用主题

Javascript - 生成相同颜色的不同阴影

Excel VBA 使用 for 循环创建下标错误

vba - 通过宏检查复选框是否被选中

c# - 更改列表框背景颜色