如何用VBA编写,把工作表中相同的字符串标记上颜色。非常感谢!

如题所述

Sub 查找相同字符串()
    I = 1
    Hs = 1
    Ls = 1
    He = Cells(65536, Ls).End(xlUp).Row
    Le = Cells(Hs, 256).End(xlToLeft).Column
    Cells.Interior.Pattern = xlNone
    For H = Hs To He
        For L = Ls To Le
            If Cells(H, L).Interior.Pattern = xlNone Then
                数值 = Cells(H, L)
                If 数值 <> "" Then
                    I = I + 1
                    Call 标记相同字符串(H, L, Hs, Ls, He, Le, 数值, I)
                End If
            End If
        Next
    Next
End Sub


Public Sub 标记相同字符串(H, L, Hs, Ls, He, Le, 数值, I)
    For HH = Hs To He
        For LL = Ls To Le
            If H <> HH Or L <> LL Then
                If 数值 = Cells(HH, LL) Then
                    Cells(H, L).Interior.Pattern = I
                    Cells(HH, LL).Interior.Pattern = I
                End If
            End If
        Next
    Next
End Sub

温馨提示:答案为网友推荐,仅供参考
相似回答