excel vba快速删除重复项

AF666:AO866区域1
1.....先将区域1还原单元格为无色
A39:J1038区域2
2.....区域1与区域2有内容重复时,将区域1重复单元填充为紫色,删除区域2重复单元内容

Sub xx()
  Set d1 = CreateObject("scripting.dictionary")
  Set d2 = CreateObject("scripting.dictionary")
  With [AF666:AO866]
    .Interior.ColorIndex = xlNone
    For i = 1 To .Count
      d1(.Item(i).Text) = ""
    Next
  End With
  With [A39:J1038]
    For i = 1 To .Count
      If d1.exists(.Item(i).Text) Then
        d2(.Item(i).Text) = ""
        .Item(i).ClearContents
      End If
    Next
  End With
  With [AF666:AO866]
    For i = 1 To .Count
      If d2.exists(.Item(i).Text) Then
        .Item(i).Interior.ColorIndex = 7
      End If
    Next
  End With
End Sub追问

现在区域1的空单元变为紫色了

    先将区域1还原单元为无色,(区域1有部分单元或空单元有颜色,所以先还原为无色)

    2。删除区域2相同的(见红色示)

    3。区域1相同的填充紫色(见紫色示)

追答Sub xx()
  Set d1 = CreateObject("scripting.dictionary")
  Set d2 = CreateObject("scripting.dictionary")
  With [AF666:AO866]
    .Interior.ColorIndex = xlNone
    For i = 1 To .Count
      If .Item(i) <> "" Then d1(.Item(i).Text) = ""
    Next
  End With
  With [A39:J1038]
    For i = 1 To .Count
      If d1.exists(.Item(i).Text) Then
        d2(.Item(i).Text) = ""
        .Item(i).ClearContents
      End If
    Next
  End With
  With [AF666:AO866]
    For i = 1 To .Count
      If d2.exists(.Item(i).Text) Then
        .Item(i).Interior.ColorIndex = 7
      End If
    Next
  End With
End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2020-04-25
相似回答