EXCEL跨表比较两列,并填充新值背景

Sub FillNewToYellow()
    Dim dic
    Dim oldArr(), updatedArr()
  
    On Error Resume Next
    If Worksheets("old") Is Nothing Then
        MsgBox "Missing old sheet"
    ElseIf Worksheets("updated") Is Nothing Then
        MsgBox "Missing updated sheet"
    Else
        Set dic = CreateObject("Scripting.Dictionary")
        ActiveWorkbook.Sheets("old").Activate
        oldArr = Range("B1:B" & ActiveSheet.UsedRange.Rows.Count)
        
        For i = 1 To UBound(oldArr)
            dic(oldArr(i, 1)) = ""
        Next
        
        ActiveWorkbook.Sheets("updated").Activate
        updatedArr = Range("B1:B" & ActiveSheet.UsedRange.Rows.Count)
        
        For i = 1 To UBound(updatedArr)
            If dic.exists(updatedArr(i, 1)) = False Then
                Rows(i & ":" & i).Select
                With Selection.Interior
                    .Pattern = xlSolid
                    .PatternColorIndex = xlAutomatic
                    .Color = 65535 'Yellow
                    .TintAndShade = 0
                    .PatternTintAndShade = 0
                End With
            End If
        Next
    End If
End Sub

原文地址:https://www.cnblogs.com/yipeng-yu/p/5556072.html