(宏代码)Execl 中 比较两个Sheet内容是否一致

自己整理的,但方法Idea是来源【TOO-布丁 (ExcelHome)http://club.excelhome.net/thread-914641-1-1.html】,故称转载


CompareSheets.bas 内容如下:


Option Explicit

Sub CompareSheets()

    Dim a As Range

    ' Init Sheets BKColor.
    Sheets("SheetA").Cells.Interior.Color = xlNone
    Sheets("SheetB").Cells.Interior.Color = xlNone
    
    For Each a In Sheets("SheetA").UsedRange
        If a.Value = Sheets("SheetB").Cells(a.Row, a.Column) Then
           
            ' TODO
        Else
        
            ' When differences were found, change color of corresponding cells.
            a.Interior.Color = RGB(255, 0, 0)
            Sheets("SheetB").Cells(a.Row, a.Column).Interior.Color = RGB(255, 0, 0)
        End If
    Next

End Sub

展开阅读全文

没有更多推荐了,返回首页