Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1987|回复: 3

[已解决]单元格中有连续数据标示颜色。

[复制链接]
发表于 2013-12-29 09:56 | 显示全部楼层 |阅读模式
单元格中有连续数据标示颜色。
最佳答案
2013-12-29 20:24
Sub test()
Dim rng As Range
Application.ScreenUpdating = 0
Set rng = Range("e20:g36")
rng.Font.ColorIndex = 1
For Each tmp In rng
    s$ = ""
    i1% = 0: i2% = 0: i3% = 0
    For Each k In Split(tmp & ",", ",")
        If s = k Then
           i1 = i1 + 1
           i3 = i3 + Len(s) + 1
        Else
           If i1 > 1 Then tmp.Characters(i2, i3).Font.ColorIndex = i1 + 1
           i1 = 1
           s = k
           i2 = i2 + i3 + 1: i3 = Len(s)
        End If
    Next
Next
End Sub

book3.zip

4.95 KB, 下载次数: 19

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2013-12-29 11:23 | 显示全部楼层
回复

使用道具 举报

发表于 2013-12-29 20:24 | 显示全部楼层    本楼为最佳答案   
Sub test()
Dim rng As Range
Application.ScreenUpdating = 0
Set rng = Range("e20:g36")
rng.Font.ColorIndex = 1
For Each tmp In rng
    s$ = ""
    i1% = 0: i2% = 0: i3% = 0
    For Each k In Split(tmp & ",", ",")
        If s = k Then
           i1 = i1 + 1
           i3 = i3 + Len(s) + 1
        Else
           If i1 > 1 Then tmp.Characters(i2, i3).Font.ColorIndex = i1 + 1
           i1 = 1
           s = k
           i2 = i2 + i3 + 1: i3 = Len(s)
        End If
    Next
Next
End Sub
回复

使用道具 举报

发表于 2014-1-6 17:46 | 显示全部楼层
3个连续相同标示颜色(即2个相同的不标示颜色),代码是修改If i1 > 2 Then tmp.Characters(i2, i3).Font.ColorIndex = i1 + 1
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-23 11:03 , Processed in 0.314506 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表