excel排序后内容相同的单元格会排在一起,现需要把这些单元格添加不同颜色,以区分,使看起来一目了然。
注意,有的单元格内容出现多次,有的仅出现一次。
如果用Excel操作无法实现,用VBA也可以。谢谢
Excel 排序后把内容相同的单元格填充颜色以区分
答案:4 悬赏:50
解决时间 2021-03-22 11:01
- 提问者网友:✐ۖ﹏ℳ๓北风
- 2021-03-22 01:20
最佳答案
- 二级知识专家网友:高冷不撩人
- 2021-03-22 02:28
操作上你只能手动完成着色,其实肉眼能明显区分的颜色数量是有限的,区分的区域多了之后首先没那么多可用颜色,如果是小部分的话,你都通过排序把单元格排到一起了,直接手动着色就可以了。Sub auto_open()
Sheet1.Select
Columns("A:A").Select '以下代码是排序
Range("A1:B16").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin, DataOption1:=xlSortNormal
Dim i, j As Integer
j = 3 'j是颜色变量
Cells(1, 1).Select '首先设定第一个表格的颜色
Selection.Font.ColorIndex = j
i = 2 'i是自动循环变量
While Not IsEmpty(Cells(i, 1))
If Cells(i, 1) = Cells(i - 1, 1) Then '如果第二个数据和上一个数据相等
Cells(i, 1).Select
Selection.Font.ColorIndex = j '使用同一个颜色代码
Else '如果不相等
j = j + 1 '使用下一个颜色代码
If j = 19 Then '颜色代码取到3至19之间,因为里面有白色和黑色,我屏蔽掉了
j = 3
End If
Cells(i, 1).Select
Selection.Font.ColorIndex = j
End If
i = i + 1
Wend
End Sub
如果你使用时,应把其中相应的行列数据修改了
Sheet1.Select
Columns("A:A").Select '以下代码是排序
Range("A1:B16").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin, DataOption1:=xlSortNormal
Dim i, j As Integer
j = 3 'j是颜色变量
Cells(1, 1).Select '首先设定第一个表格的颜色
Selection.Font.ColorIndex = j
i = 2 'i是自动循环变量
While Not IsEmpty(Cells(i, 1))
If Cells(i, 1) = Cells(i - 1, 1) Then '如果第二个数据和上一个数据相等
Cells(i, 1).Select
Selection.Font.ColorIndex = j '使用同一个颜色代码
Else '如果不相等
j = j + 1 '使用下一个颜色代码
If j = 19 Then '颜色代码取到3至19之间,因为里面有白色和黑色,我屏蔽掉了
j = 3
End If
Cells(i, 1).Select
Selection.Font.ColorIndex = j
End If
i = i + 1
Wend
End Sub
如果你使用时,应把其中相应的行列数据修改了
全部回答
- 1楼网友:24K纯糖
- 2021-03-22 05:14
油漆桶·· 可以填充表格
- 2楼网友:滚出爷的世界
- 2021-03-22 03:38
操作上你只能手动完成着色,其实肉眼能明显区分的颜色数量是有限的,区分的区域多了之后首先没那么多可用颜色,如果是小部分的话,你都通过排序把单元格排到一起了,直接手动着色就可以了,没必要把简单的事情搞复杂
- 3楼网友:不服输的倔强
- 2021-03-22 02:48
Sub auto_open()
Sheet1.Select
Columns("A:A").Select '以下代码是排序
Range("A1:B16").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin, DataOption1:=xlSortNormal
Dim i, j As Integer
j = 3 'j是颜色变量
Cells(1, 1).Select '首先设定第一个表格的颜色
Selection.Font.ColorIndex = j
i = 2 'i是自动循环变量
While Not IsEmpty(Cells(i, 1))
If Cells(i, 1) = Cells(i - 1, 1) Then '如果第二个数据和上一个数据相等
Cells(i, 1).Select
Selection.Font.ColorIndex = j '使用同一个颜色代码
Else '如果不相等
j = j + 1 '使用下一个颜色代码
If j = 19 Then '颜色代码取到3至19之间,因为里面有白色和黑色,我屏蔽掉了
j = 3
End If
Cells(i, 1).Select
Selection.Font.ColorIndex = j
End If
i = i + 1
Wend
End Sub '全代码测试通过的,如果你使用时,应把其中相应的行列数据修改了.祝顺利使用.ofmfu.
=============楼下的sb,抄袭我的还在本页发..
我晕,,怎么修改一次答案还跑下面来了..
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯