不同表格查找重复数据VBA

分析两个表格中对应列的重复情况。

Sub Match_Dec()
    '两个表格,表格中的某一列为对应列,查找这两列中的重复记录和差异记录。
    
    Dim ar As Long, br As Long, i As Integer, j As Integer, num As Integer
        'ar/br为行数,i为外层循环数控制,j为内层循环数控制
    Dim A_Range As Range, B_Range As Range
    Dim myFont As Font
    
    Set A_Range = Worksheets("Sheet4").UsedRange
    Set B_Range = Worksheets("Sheet5").UsedRange
    
    ar = A_Range.Rows.Count
    br = B_Range.Rows.Count
    
    num = 0
'查找重复行
    
    For i = 1 To ar
        Debug.Print "第" & i; "行"
        For j = 1 To br
            If A_Range.Cells(i, 1) = B_Range.Cells(j, 1) Then
                Debug.Print "第" & j; "行为重复行"
'                'myRange.Cells(i, 1).EntireRow.Delete shift:=xlShiftUp 'xlShiftToLeft
'
                Set myFont = A_Range.Cells(i, 1).EntireRow.Font
                'Set myFont = B_Range.Cells(j, 1).EntireRow.Font
                With myFont
                .Name = "楷体"
                .Size = 15
                .Bold = True
                .Italic = True
                .Color = RGB(255, 0, 0)
                .Strikethrough = True '水平删除线
                .Underline = xlUnderlineStyleNone 'xlUnderlineStyleSingle 'xlUnderlineStyleDouble
                .Shadow = False  '是/否无变化??
                .Subscript = False
                .Superscript = False
                '具体属性设置参看:https://docs.microsoft.com/zh-cn/office/vba/api/excel.xlpattern
                End With
                
                num = num + 1
            End If
         Next
    Next
    
    Debug.Print "共有" & num & "重复行"
End Sub
    原文作者:l_iu_xing
    原文地址: https://blog.csdn.net/l_iu_xing/article/details/85246756
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞