找出EXCEL中值相同的单元格并且按不同的颜色标识

Sub Macro1()
Dim arr, i, j
Dim d As Object, mkey
 Dim mHight, s
'On Error Resume Next
Set d = CreateObject("scripting.dictionary")
d.CompareMode = TextCompare
arr = Range("A1:E21")
For j = 1 To 5
 For i = 1 To UBound(arr)
 If Len(arr(i, j)) <> 0 Then
d(arr(i, j)) = d(arr(i, j)) & "," & Chr(j + 64) & i
 End If
 Next
 Next
For Each mkey In d.keys
    If UBound(Split(d(mkey), ",")) > 1 Then
    mHight = mHight + 16
    s = mkey & "有重复,位置为:" & Mid(d(mkey), 2) & Chr(10) & s
    Dim strCity()     As String
    strCity = Split(Mid(d(mkey), 2), ",")
    For intloop = 0 To UBound(strCity)
        Range(strCity(intloop)).Select
        x = Int(Rnd() * 255)
        y = Int(Rnd() * 255)
        Z = Int(Rnd() * 255)
        With Selection.Font
            '.Color = RGB(x, y, Z)
            .TintAndShade = 0
        End With
        With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = RGB(x, y, Z)
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Next intloop
End If
Next

If mHight = 0 Then
    TextBox1.Text = "没有发现重复单元格"
Else
    MsgBox (s)
End If
End Sub

转载于:https://www.cnblogs.com/chinhr/archive/2010/03/10/1682389.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值